Merge branch 'main' into feature/regression-arcgis300-symbology-migration
This commit is contained in:
82 files changed
+13847
No files matched your search
Vendored
+77
@@ -0,0 +1,77 @@
|
||||
9868119af0684e4e99c1ed9cba2467a0975ba008d27f48677eb8620b7d1256f6 include/dtEntity/uniqueid.h
|
||||
b9d8449804ff68862456837f63be414e71950e63bf8343d2c9aef0c325aec470 include/dtEntity/message.h
|
||||
94d95c7077037165b79923cedb08a3b62b5fe9338bd97ecdcf05ae60c95ec2d1 include/dtEntity/componentpluginmanager.h
|
||||
4bb43f0207e24ac952841169f4ef7156e48dbaeb5485ee9da8f32321828cbeb1 include/dtEntity/entityid.h
|
||||
1c55a6c6bef49b24e8488ab39c296d33bb8726d3ca9f6236729642e18b1af2ce include/dtEntity/componentplugin.h
|
||||
d48c081fc472f66b390cc9dde2b259d39a1e1f221c39d3a6a8b624d63561088d include/dtEntity/systemmessages.h
|
||||
36a06cbab8eba491c688bcb7a2c9ee90e03293b47f02aadd7521edba245d3799 include/dtEntity/commandmessages.h
|
||||
ec501b8fa2b5546260aa1d0e0562cd6c147e25a42bb4bea8b9c2110a7d9cfb47 include/dtEntity/rapidxmlmapencoder.h
|
||||
dc29c99d8f90753efe032612e9208ef6d1eef1877f7b30996c11c74067f66bd6 include/dtEntity/resourcemanager.h
|
||||
15bff21fa47e10c24491065578ada0484f1239ce112361c5b3b927f593703c20 include/dtEntity/objectfactory.h
|
||||
7a06ef09fef3b24201db22d158e1070768e57a411845eedccbe3ef34cfa5c492 include/dtEntity/init.h
|
||||
3a55f8d8396e754f4551959947270bdc556f67981579ef38f88cf1a1007b36dc include/dtEntity/dynamicscomponent.h
|
||||
2d62c6ddb60b1e60b43a2c8e838b29acc0cbccd63815a266fae0530b53503219 include/dtEntity/defaultentitysystem.h
|
||||
a42c0e9a6c0a0a1d015becfcd71a1875b2fc30890073c274df9bdc950c94fdae include/dtEntity/component.h
|
||||
e7eab19ef1d6cafcd3dcb0a09147e8139c91d8ea7ebee1a6618de42dc01e2ab2 include/dtEntity/entitysystem.h
|
||||
7393a2e3379839dc356839a0f56672d11b869ea6ba6f9b6d82d6381722cced49 include/dtEntity/log.h
|
||||
878fbb00aa2d70aab2a1af86592f29c5f58ccd5d25da80fa5624147e91ddb007 include/dtEntity/debugdrawinterface.h
|
||||
e46d71595270c3b6ce198a9d7bd6f86c0339fd91954f62fa6e4967e7496a1acb include/dtEntity/messagefactory.h
|
||||
e9d568c7ef79dedb6ce31e79b188ccad51459953b3b6d7af818bc805a2189b4d include/dtEntity/entity.h
|
||||
85bec4e84332250d77a0efe3052c2278ad6cacf0174d86e90503d890168ffe9d include/dtEntity/core.h
|
||||
8df252d57ff7c706e3829717f1ba15d41589df164ba0d7b2f943238396f2082a include/dtEntity/property.h
|
||||
eb3f0bac95a19544209e9a83992e91686b43b3893de59c8d0adb7d6192f6f03b include/dtEntity/nodemasks.h
|
||||
f6892d4f780e5e9e6bb05cfa449264875497f6676c5bfebbd22b89818ec46d5b include/dtEntity/systeminterface.h
|
||||
d1d30e7cf79fd024c3469bf689d297083c3a496a962fffbe8ceb4831057f8992 include/dtEntity/logmanager.h
|
||||
fcdd4b252244d719a4d1393a0dca4d356214415414b565b0d2d9a408d5d1b234 include/dtEntity/messagepump.h
|
||||
d9bd24dfd49b7960fe4af0030b07db1c51dd4b67905ea60a746486ffcec2b6e7 include/dtEntity/mapencoder.h
|
||||
7052bf8dad130f11a0ca90ac4b99c0193ec0804d5c013c9de976e982779001a4 include/dtEntity/threadsafequeue.h
|
||||
7a03404655a1cbfe53876ddc4f2b674fd7f8cea4f2a7840823f0de88891d61bb include/dtEntity/hash.h
|
||||
72b6fdf2e69fb2aafc82c9bcc55598b2abbca23de372fa8a4a17ddaec1fb0052 include/dtEntity/stringid.h
|
||||
43900165545bc2f58dc471ad6df44cd32c6c1b65295cb31d55ce6e277ec5b00b include/dtEntity/FastDelegateBind.h
|
||||
1fc0ff1802c1bb408f7c92a9faa03370dc90875359868cd2fe220022e02719ec include/dtEntity/singleton.h
|
||||
c51e323a7b4b866772b037dd37bcacb06abed37a7d09809ccd9ce37bd150e792 include/dtEntity/dtentity_config.h
|
||||
af0fccd4d374417767b100340b67a8d8e60e46fced6a2fabd6a29f41013ad808 include/dtEntity/propertycontainer.h
|
||||
a37d096e665458feeb9baf4a4cec9fe118749c162c2b9b8d83e81783b9208423 include/dtEntity/FastDelegate.h
|
||||
4031bc03599cc5170208dc475598a08e3032e811e372f46ae6a63309db9cc98d include/dtEntity/export.h
|
||||
a31be0ad4cd4e8459711c24a6f95a16aae3e17c3620cb05d62b279b7b3372684 include/dtEntity/componentfactories.h
|
||||
ec069ef6e81d24d048086c1d1b2502f357727f18c6a04873a22dff3eed3aea7d include/dtEntity/inputinterface.h
|
||||
910a99cc0a3b9707edd71ab23b34387d7187643119e5de2a41aadc94abeba54a include/dtEntity/mapcomponent.h
|
||||
c0a7145cc66bce93099d987db2b56e676a6a30bdfa5dd9eb7f67f5bd9eaa1841 include/dtEntity/entitymanager.h
|
||||
62542af7a60195130656c8301fbb90958662a2283bd3c91414f3c732e6c5d08f include/dtEntity/scriptaccessor.h
|
||||
b7ed64365af8825f25071dfb79680b516127bb2e19836057c88487bd90a2ab4d include/dtEntity/dynamicproperty.h
|
||||
4fe56800e56ff32470850f66c8d6d8ccc48161f4bf2cd29a50810bad2cdda8f2 include/dtEntity/profile.h
|
||||
73f4c01b1d042385f38aac9e65e344ac300544c361f8ee6e40773760ee05428d include/dtEntity/spawner.h
|
||||
5a2048cf4b86885b935b11511693fae5277ffa010587ad9f0e958bff86f36812 include/dtEntity/windowinterface.h
|
||||
f1e3efe39a3b934a9faae9221dc7bbc0711fa903af99f2963faee69efa7de232 include/dtEntityOSG/osgwindowinterface.h
|
||||
8713fcb916ba43c8673cf7793144ab99cf25083e14364b9e587132fcb84df348 include/dtEntityOSG/manipulators.h
|
||||
9efa10d5f622041f2ae6bb65ff03ca1ecbcf82cecb3c4da81157efd888375b38 include/dtEntityOSG/dtentityosg_config.h
|
||||
8f5f61c9dc8afcaac610065a9df59abb2d04f3e01bb1e4b98b91d95a4f8de53d include/dtEntityOSG/shadowcomponent.h
|
||||
3d14380981d053894b50c04d369bd630abaa91de3ca149cd88234afb409b4d72 include/dtEntityOSG/matrixtransformcomponent.h
|
||||
ea144f7e4dd348a8055b6cf93f7ab2d2064ba8b629e275820ed00d1d987f8a07 include/dtEntityOSG/skyboxcomponent.h
|
||||
a5df06c916c6c7856d1aada7ad30be6fbb64a52bcad4afaee1f983f3ae186022 include/dtEntityOSG/osgsysteminterface.h
|
||||
fc0575923dbb26a5aff98b75c611679182bac3284871a1e49f89df1afdb1e13f include/dtEntityOSG/layerattachpointcomponent.h
|
||||
d0bac5bbce68a0245b7dc61d10510414caf51da212b307504e337ee543e70919 include/dtEntityOSG/manipulatorcomponent.h
|
||||
b3fdfbf73131012f3257376197413618aea27e6ee1455b45c1fbc3be583130cb include/dtEntityOSG/groupcomponent.h
|
||||
7ed7b55c32b9e6b7e97e8c65f0b68d513871d2510eaf8a8f307829c84a4f4a20 include/dtEntityOSG/particlecomponent.h
|
||||
a38a57b8a6249db2c70975c8abfc01feab7e081ebae30e58282d6d6018c8aa2e include/dtEntityOSG/pickshapecomponent.h
|
||||
13de73aaf7fea9a99ce664ae97701fbf67560de0ffa621fa0a1b49bfdf516b86 include/dtEntityOSG/transformcomponent.h
|
||||
6388d185f519daf05b902c209c8c110df1d737c4b8a67c34b54761085400f2a7 include/dtEntityOSG/positionattitudetransformcomponent.h
|
||||
0ec8625684c80c4dee2503049713ba211c7a8a797725a1a2a259dd256a9fe9d0 include/dtEntityOSG/nodemaskvisitor.h
|
||||
b6dbcbd009d13ebb77fa2a8b0afcaee49091dfe2256a5f5ee0c565f481a37257 include/dtEntityOSG/cameracomponent.h
|
||||
3832a4510119355eb8e5223e0f1dda4ce35b9a1893df2fdb596fca6f4b22bbd1 include/dtEntityOSG/texturelabelcomponent.h
|
||||
e1018dee953405755612ffedb63edeab3a8607d9034f842aa31d12b4235023a6 include/dtEntityOSG/osgdebugdrawinterface.h
|
||||
6789588e699e3a23413fa24610203cbc7ab330570bd8684099cd96257420318a include/dtEntityOSG/textlabelcomponent.h
|
||||
a41676f8a8f92e5418b4cddb97c9c33c546c67e82b4abd5f6d3bcba407966f2c include/dtEntityOSG/lightcomponent.h
|
||||
e7a38d6f058b6828405f85a2809f9627100b5897cd70b1581cca3d0a895a80ee include/dtEntityOSG/nodecomponent.h
|
||||
bf41c7204151b1ee0d3694f79e1c160a47f323be3c216fd41f714d3d9230ab87 include/dtEntityOSG/pathcomponent.h
|
||||
0a5ffc701caff5fc8a0f19289191a968794454a991406189b2b239b0e5a0b185 include/dtEntityOSG/osganimationcomponent.h
|
||||
bb8443325f3c9771a3540e72e7e19c75b7efc31a2c769aeaf4e535c1c78083b5 include/dtEntityOSG/initosgviewer.h
|
||||
a5429771833ae4182491afd334fe5339a8c2764299c03ed775bd6350efa79b20 include/dtEntityOSG/layercomponent.h
|
||||
11294ef13d0c3edb95399045a43d2a5eef56f5e6f42175620c3abbaf1b732a17 include/dtEntityOSG/export.h
|
||||
7950331766ea9f639a3754fd5ad614f88bbd23f6dfff07c2057c08c6d9e550f3 include/dtEntityOSG/componentfactories.h
|
||||
a4ff0c401dfb0bc19d00deb0191dcc1c06a50c0b74a3df4eb61238196efa238d include/dtEntityOSG/staticmeshcomponent.h
|
||||
bcc988d0acd140551743e27d8de9885ce9d3b7b5844b0b78eca267ec54d2a1be include/dtEntityOSG/groundclampingcomponent.h
|
||||
8dad8e47fb56991ca74a46ad6d701158c0ffd9eda0099f433fa817a048ff9f84 include/dtEntityOSG/osginputinterface.h
|
||||
e4c13fc3cb01c49ec18c8352a8e97599533c6b84b4ccf398dbdbd559415a1409 include/dtEntityOSG/shadercomponent.h
|
||||
b920d50872ad2537b56832c36c1165a5ae53ee6981549235b8b8921ed1255273 lib64/libdtEntityOSG.so.0.1.1
|
||||
f53dababd2d92c96adf2f4d43c5c1b53acb1b4894f820e2e7a1226c230f1f8b6 lib64/libdtEntity.so.0.1.1
|
||||
+2111
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,245 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FASTDELEGATEBIND_H
|
||||
#define FASTDELEGATEBIND_H
|
||||
|
||||
// FastDelegateBind.h
|
||||
// Helper file for FastDelegates. Provides bind() function, enabling
|
||||
// FastDelegates to be rapidly compared to programs using boost::function and boost::bind.
|
||||
//
|
||||
// Documentation is found at http://www.codeproject.com/cpp/FastDelegate.asp
|
||||
//
|
||||
// Original author: Jody Hagins.
|
||||
// Minor changes by Don Clugston.
|
||||
//
|
||||
// Warning: The arguments to 'bind' are ignored! No actual binding is performed.
|
||||
// The behaviour is equivalent to boost::bind only when the basic placeholder
|
||||
// arguments _1, _2, _3, etc are used in order.
|
||||
//
|
||||
// HISTORY:
|
||||
// 1.4 Dec 2004. Initial release as part of FastDelegate 1.4.
|
||||
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// FastDelegate bind()
|
||||
//
|
||||
// bind() helper function for boost compatibility.
|
||||
// (Original author: Jody Hagins).
|
||||
//
|
||||
// Add another helper, so FastDelegate can be a dropin replacement
|
||||
// for boost::bind (in a fair number of cases).
|
||||
// Note the elipses, because boost::bind() takes place holders
|
||||
// but FastDelegate does not care about them. Getting the place holder
|
||||
// mechanism to work, and play well with boost is a bit tricky, so
|
||||
// we do the "easy" thing...
|
||||
// Assume we have the following code...
|
||||
// using boost::bind;
|
||||
// bind(&Foo:func, &foo, _1, _2);
|
||||
// we should be able to replace the "using" with...
|
||||
// using fastdelegate::bind;
|
||||
// and everything should work fine...
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX
|
||||
|
||||
namespace fastdelegate {
|
||||
|
||||
//N=0
|
||||
template <class X, class Y, class RetType>
|
||||
FastDelegate< RetType ( ) >
|
||||
bind(
|
||||
RetType (X::*func)( ),
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( ) >(y, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class RetType>
|
||||
FastDelegate< RetType ( ) >
|
||||
bind(
|
||||
RetType (X::*func)( ) const,
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( ) >(y, func);
|
||||
}
|
||||
|
||||
//N=1
|
||||
template <class X, class Y, class RetType, class Param1>
|
||||
FastDelegate< RetType ( Param1 p1 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1 ),
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1 ) >(y, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class RetType, class Param1>
|
||||
FastDelegate< RetType ( Param1 p1 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1 ) const,
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1 ) >(y, func);
|
||||
}
|
||||
|
||||
//N=2
|
||||
template <class X, class Y, class RetType, class Param1, class Param2>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2 ),
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2 ) >(y, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class RetType, class Param1, class Param2>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2 ) const,
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2 ) >(y, func);
|
||||
}
|
||||
|
||||
//N=3
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3 ),
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >(y, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3 ) const,
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >(y, func);
|
||||
}
|
||||
|
||||
//N=4
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ),
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >(y, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const,
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >(y, func);
|
||||
}
|
||||
|
||||
//N=5
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ),
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >(y, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const,
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >(y, func);
|
||||
}
|
||||
|
||||
//N=6
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ),
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >(y, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const,
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >(y, func);
|
||||
}
|
||||
|
||||
//N=7
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ),
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >(y, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const,
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >(y, func);
|
||||
}
|
||||
|
||||
//N=8
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ),
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >(y, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
|
||||
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >
|
||||
bind(
|
||||
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const,
|
||||
Y * y,
|
||||
...)
|
||||
{
|
||||
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >(y, func);
|
||||
}
|
||||
|
||||
|
||||
#endif //FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX
|
||||
|
||||
} // namespace fastdelegate
|
||||
|
||||
#endif // FASTDELEGATEBIND_H
|
||||
@@ -0,0 +1,457 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/property.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* These messages can be sent by user code to trigger a reaction in
|
||||
* a dtEntity subsystem.
|
||||
*/
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class MessageFactory;
|
||||
|
||||
/**
|
||||
* Adds all messages to message factory
|
||||
*/
|
||||
void DT_ENTITY_EXPORT RegisterCommandMessages(MessageFactory&);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Send this message to cause the map system to remove an entity from
|
||||
* scene and delete it
|
||||
*/
|
||||
class DT_ENTITY_EXPORT DeleteEntityMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId UniqueIdId;
|
||||
|
||||
DeleteEntityMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<DeleteEntityMessage>(); }
|
||||
|
||||
void SetUniqueId(const std::string& v) { mUniqueId.Set(v); }
|
||||
std::string GetUniqueId() const { return mUniqueId.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mUniqueId;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Systems can react to this message by enabling their debug drawing.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EnableDebugDrawingMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId EnableId;
|
||||
|
||||
EnableDebugDrawingMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<EnableDebugDrawingMessage>(); }
|
||||
|
||||
bool GetEnable() const { return mEnable.Get(); }
|
||||
void SetEnable(bool v){ mEnable.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
BoolProperty mEnable;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Cause camera to be moved to entity
|
||||
*/
|
||||
class DT_ENTITY_EXPORT MoveCameraToEntityMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId DistanceId;
|
||||
static const StringId KeepCameraDirectionId;
|
||||
static const StringId ContextIdId;
|
||||
|
||||
MoveCameraToEntityMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<MoveCameraToEntityMessage>(); }
|
||||
|
||||
EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); }
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); }
|
||||
|
||||
// default is 10
|
||||
double GetDistance() const { return mDistance.Get(); }
|
||||
void SetDistance(double v) { mDistance.Set(v); }
|
||||
|
||||
// if true: current eye direction of camera is preserved.
|
||||
// if false: rotate camera from current position to target entity, then
|
||||
// move until distance is reached
|
||||
// true by default
|
||||
bool GetKeepCameraDirection() const { return mKeepCameraDirection.Get(); }
|
||||
void SetKeepCameraDirection(bool v) { mKeepCameraDirection.Set(v); }
|
||||
|
||||
// camera context
|
||||
int GetContextId() const { return mContextId.Get(); }
|
||||
void SetContextId(int v) { mContextId.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntityId;
|
||||
DoubleProperty mDistance;
|
||||
BoolProperty mKeepCameraDirection;
|
||||
IntProperty mContextId;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Cause camera to be moved to a specific position
|
||||
*/
|
||||
class DT_ENTITY_EXPORT MoveCameraToPositionMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId PositionId;
|
||||
static const StringId LookAtId;
|
||||
static const StringId UpId;
|
||||
static const StringId ContextIdId;
|
||||
|
||||
MoveCameraToPositionMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<MoveCameraToPositionMessage>(); }
|
||||
|
||||
Vec3d GetPosition() const { return mPosition.Get(); }
|
||||
void SetPosition(const Vec3d& v) { mPosition.Set(v); }
|
||||
|
||||
// if same as position: Look in direction of movement from last position
|
||||
Vec3d GetLookAt() const { return mLookAt.Get(); }
|
||||
void SetLookAt(const Vec3d& v) { mLookAt.Set(v); }
|
||||
|
||||
Vec3f GetUp() const { return mUp.Get(); }
|
||||
void SetUp(const Vec3f& v) { mUp.Set(v); }
|
||||
|
||||
// camera context
|
||||
int GetContextId() const { return mContextId.Get(); }
|
||||
void SetContextId(int v) { mContextId.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
Vec3dProperty mPosition;
|
||||
Vec3dProperty mLookAt;
|
||||
Vec3Property mUp;
|
||||
IntProperty mContextId;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Cause an animation to be played
|
||||
*/
|
||||
class DT_ENTITY_EXPORT PlayAnimationMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId AnimationNameId;
|
||||
|
||||
PlayAnimationMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<PlayAnimationMessage>(); }
|
||||
|
||||
EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); }
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); }
|
||||
|
||||
std::string GetAnimationName() const { return mAnimationName.Get(); }
|
||||
void SetAnimationName(const std::string& id) { mAnimationName.Set(id); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntityId;
|
||||
StringProperty mAnimationName;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT RequestEntityDeselectMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
|
||||
RequestEntityDeselectMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<RequestEntityDeselectMessage>(); }
|
||||
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); }
|
||||
EntityId GetAboutEntityId() const { return mAboutEntity.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntity;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT RequestEntitySelectMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId UseMultiSelectId;
|
||||
|
||||
RequestEntitySelectMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<RequestEntitySelectMessage>(); }
|
||||
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); }
|
||||
EntityId GetAboutEntityId() const { return mAboutEntity.Get(); }
|
||||
|
||||
void SetUseMultiSelect(bool v) { mUseMultiSelect.Set(v); }
|
||||
bool GetUseMultiSelect() const { return mUseMultiSelect.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntity;
|
||||
BoolProperty mUseMultiSelect;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT RequestToggleEntitySelectionMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
|
||||
RequestToggleEntitySelectionMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<RequestToggleEntitySelectionMessage>(); }
|
||||
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); }
|
||||
EntityId GetAboutEntityId() const { return mAboutEntity.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntity;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Application system reacts to this message by retrieving a component of type t
|
||||
* from entity identified by id and applying the property values of mProperty
|
||||
* to the component.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT SetComponentPropertiesMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId EntityUniqueIdId;
|
||||
static const StringId ComponentTypeId;
|
||||
static const StringId PropertiesId;
|
||||
|
||||
SetComponentPropertiesMessage();
|
||||
|
||||
/**
|
||||
* Initialize with single property. Prop is cloned!
|
||||
*/
|
||||
SetComponentPropertiesMessage(const std::string& entityUniqueId,
|
||||
const std::string& componenttype, const std::string& propname, Property& prop);
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<SetComponentPropertiesMessage>(); }
|
||||
|
||||
std::string GetEntityUniqueId() const { return mEntityUniqueId.Get(); }
|
||||
void SetEntityUniqueId(const std::string& id) { mEntityUniqueId.Set(id); }
|
||||
|
||||
void SetComponentType(const std::string& t) { mComponentType.Set(t); }
|
||||
std::string GetComponentType() const { return mComponentType.Get(); }
|
||||
|
||||
/**
|
||||
* Group of properties that will be applied to entity system
|
||||
*/
|
||||
void SetComponentProperties(PropertyGroup& v) { mProperties.Set(v); }
|
||||
const PropertyGroup& GetComponentProperties() const { return mProperties.Get(); }
|
||||
|
||||
private:
|
||||
StringProperty mComponentType;
|
||||
GroupProperty mProperties;
|
||||
StringProperty mEntityUniqueId;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Application system reacts to this message by retrieving the entity system
|
||||
* of type t and applying the property values of mProperty to the entity system.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT SetSystemPropertiesMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId ComponentTypeId;
|
||||
static const StringId PropertiesId;
|
||||
|
||||
SetSystemPropertiesMessage();
|
||||
|
||||
/**
|
||||
* Initialize with single property. Prop is cloned!
|
||||
*/
|
||||
SetSystemPropertiesMessage(const std::string& componenttype, const std::string& propname, Property& prop);
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<SetSystemPropertiesMessage>(); }
|
||||
|
||||
void SetComponentType(const std::string& t) { mComponentType.Set(t); }
|
||||
std::string GetComponentType() const { return mComponentType.Get(); }
|
||||
|
||||
/**
|
||||
* Group of properties that will be applied to entity system
|
||||
*/
|
||||
void SetSystemProperties(PropertyGroup& v) { mProperties.Set(v); }
|
||||
const PropertyGroup& GetSystemProperties() const { return mProperties.Get(); }
|
||||
|
||||
private:
|
||||
StringProperty mComponentType;
|
||||
GroupProperty mProperties;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* User can send this message to cause the map system to spawn an entity from the given spawner.
|
||||
* The contained unique id will be assigned to the spawned entity.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT SpawnEntityMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId UniqueIdId;
|
||||
static const StringId EntityNameId;
|
||||
static const StringId SpawnerNameId;
|
||||
static const StringId AddToSceneId;
|
||||
SpawnEntityMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<SpawnEntityMessage>(); }
|
||||
|
||||
void SetUniqueId(const std::string& v) { mUniqueId.Set(v); }
|
||||
std::string GetUniqueId() const { return mUniqueId.Get(); }
|
||||
|
||||
std::string GetSpawnerName() const { return mSpawnerName.Get(); }
|
||||
void SetSpawnerName(const std::string& v) { mSpawnerName.Set(v); }
|
||||
|
||||
std::string GetEntityName() const { return mEntityName.Get(); }
|
||||
void SetEntityName(const std::string& v) { mEntityName.Set(v); }
|
||||
|
||||
bool GetAddToScene() const { return mAddToScene.Get(); }
|
||||
void SetAddToScene(bool v) { mAddToScene.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mUniqueId;
|
||||
StringProperty mEntityName;
|
||||
StringProperty mSpawnerName;
|
||||
BoolProperty mAddToScene;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Send this to cause the tool system to switch to using the named tool
|
||||
*/
|
||||
class DT_ENTITY_EXPORT ToolActivatedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId ToolNameId;
|
||||
|
||||
ToolActivatedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<ToolActivatedMessage>(); }
|
||||
|
||||
void SetToolName(const std::string& n) { mToolName.Set(n); }
|
||||
std::string GetToolName() const { return mToolName.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mToolName;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/** send this when you have added or removed a tool from tool manager
|
||||
* mTools property should have data in this format:
|
||||
* mtools contains a number of group properties.
|
||||
* Each group property has entries
|
||||
* StringProperty "ToolName" - name of tool as registered in tool manager
|
||||
* StringProperty "IconPath" - path to icon to display for tool
|
||||
* StringProperty "Shortcut" - keyboard shortcut for tool, example: "Ctrl+t"
|
||||
*/
|
||||
class DT_ENTITY_EXPORT ToolsUpdatedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId ToolsId;
|
||||
static const StringId ToolNameId;
|
||||
static const StringId IconPathId;
|
||||
static const StringId ShortcutId;
|
||||
|
||||
ToolsUpdatedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<ToolsUpdatedMessage>(); }
|
||||
|
||||
void SetTools(const PropertyArray& n) { mTools.Set(n); }
|
||||
PropertyArray GetTools() const { return mTools.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
ArrayProperty mTools;
|
||||
};
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/propertycontainer.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class Entity;
|
||||
|
||||
/**
|
||||
* Components are lightweight property containers.
|
||||
* Components can be used as per-entity data storage for entity systems.
|
||||
* It is probably best to keep components as slim as possible and
|
||||
* keep the logic in the entity systems.
|
||||
*/
|
||||
class Component
|
||||
: public PropertyContainer
|
||||
{
|
||||
public:
|
||||
|
||||
Component() {}
|
||||
virtual ~Component() {}
|
||||
|
||||
/**
|
||||
* Return a unique identifier for this component
|
||||
*/
|
||||
virtual ComponentType GetType() const = 0;
|
||||
|
||||
/**
|
||||
* Gets called when component is instantiated
|
||||
*/
|
||||
virtual void OnAddedToEntity(Entity& entity) {}
|
||||
|
||||
/**
|
||||
* Gets called right before component is deleted
|
||||
*/
|
||||
virtual void OnRemovedFromEntity(Entity& entity) {}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class ComponentPluginManager;
|
||||
void DT_ENTITY_EXPORT RegisterStandardFactories(dtEntity::ComponentPluginManager& pluginManager);
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <list>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osgDB/DynamicLibrary>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class EntityManager;
|
||||
class EntitySystem;
|
||||
|
||||
|
||||
/**
|
||||
* PluginFactory is a pure virtual interface for the values
|
||||
* returned by an entity system plugin entry point.
|
||||
* The plugin factories are stored in the plugin manager and are used to list available
|
||||
* entity systems, start and stop them.
|
||||
*/
|
||||
class ComponentPluginFactory
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~ComponentPluginFactory()
|
||||
{
|
||||
}
|
||||
|
||||
/** get the name of the entity system (the type string) */
|
||||
virtual std::string GetName() const = 0;
|
||||
|
||||
/**
|
||||
* Implementations should construct their entity system now and assign it to es variable
|
||||
* Return true if success, else false
|
||||
*/
|
||||
virtual bool Create(EntityManager* em, EntitySystem*& es) = 0;
|
||||
|
||||
/** delete the entity system */
|
||||
virtual void Destroy() {}
|
||||
|
||||
/**
|
||||
* return a textual description of the entity system functionality
|
||||
*/
|
||||
virtual std::string GetDescription() const { return ""; }
|
||||
|
||||
/**
|
||||
* fill list with types of all entity systems this system depends on.
|
||||
* WARNING: circular dependencies are not handled and
|
||||
* will cause a crash!
|
||||
*/
|
||||
virtual void GetDependencies(std::list<ComponentType>&) {}
|
||||
|
||||
osgDB::DynamicLibrary* GetLibrary() const { return mLibrary.get(); }
|
||||
void SetLibrary(osgDB::DynamicLibrary* l) { mLibrary = l; }
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<osgDB::DynamicLibrary> mLibrary;
|
||||
};
|
||||
|
||||
template <class ES>
|
||||
class ComponentPluginFactoryImpl : public ComponentPluginFactory
|
||||
{
|
||||
public:
|
||||
|
||||
ComponentPluginFactoryImpl(const std::string& name, const std::string& desc = "")
|
||||
: mName(name)
|
||||
, mDesc(desc)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool Create(EntityManager* em, EntitySystem*& es)
|
||||
{
|
||||
es = new ES(*em);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** get the name of the plugin */
|
||||
virtual std::string GetName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
/** get a description of the plugin */
|
||||
virtual std::string GetDescription() const
|
||||
{
|
||||
return mDesc;
|
||||
}
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mDesc;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/singleton.h>
|
||||
#include <dtEntity/componentplugin.h>
|
||||
#include <dtEntity/dtentity_config.h>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class MessageFactory;
|
||||
|
||||
void DT_ENTITY_EXPORT AddToList(std::list<dtEntity::ComponentPluginFactory*>& lst, int count, ...);
|
||||
|
||||
// typedef for function pointer to get message factory from library
|
||||
typedef void (*RegisterMessagesFn)(MessageFactory&);
|
||||
|
||||
// typedef for function pointer to get entity system factory from library
|
||||
typedef void (*CreatePluginFactoriesFn)(std::list<ComponentPluginFactory*>&);
|
||||
|
||||
/**
|
||||
* The plugin manager is responsible for loading entity system factories from plugins,
|
||||
* keep them around until they are needed, and start and stop the entity systems.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT ComponentPluginManager
|
||||
: public Singleton<ComponentPluginManager>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
ComponentPluginManager();
|
||||
~ComponentPluginManager();
|
||||
|
||||
typedef std::map<ComponentType, ComponentPluginFactory*> PluginFactoryMap;
|
||||
typedef std::set<ComponentType> ActivePlugins;
|
||||
|
||||
/**
|
||||
* is there a factory for an entity system of this type?
|
||||
*/
|
||||
bool FactoryExists(ComponentType ctype);
|
||||
|
||||
/**
|
||||
* load all libraries in dir and add component factories to registry
|
||||
*/
|
||||
void LoadPluginsInDir(const std::string& path);
|
||||
|
||||
/**
|
||||
* If entity of this type is registered, start it and add it to entity manager.
|
||||
* @param name Name of plugin to start
|
||||
* @return true if success
|
||||
*/
|
||||
bool StartEntitySystem(EntityManager&, ComponentType ctype);
|
||||
|
||||
/**
|
||||
* stop all entity systems loaded from plugins and then unref the plugins
|
||||
*/
|
||||
void UnloadAllPlugins(EntityManager&);
|
||||
|
||||
/**
|
||||
* Directly add a factory for starting an entity system (instead of loading
|
||||
* it from a plugin
|
||||
*/
|
||||
bool AddFactory(ComponentPluginFactory* factory);
|
||||
|
||||
/**
|
||||
* Load a shared library / dll from abs path and register
|
||||
* the contained entity system factories
|
||||
* A library can also be stored in the scene file, if desired (this can make it easier
|
||||
* for applications to know what specific plugins to load).
|
||||
* @abspath File name with path of plugin to load
|
||||
* @saveWithScene Flag to tell if library will be saved with the scene (false by default)
|
||||
*
|
||||
* @return The list of new component types loaded from the plugin
|
||||
*/
|
||||
std::set<ComponentType> AddPlugin(const std::string& abspath, bool saveWithScene = false);
|
||||
|
||||
/**
|
||||
* same as before, but doesn't expect a full path to plugin, instead takes
|
||||
* a plugin directory and a library name without extension.
|
||||
*/
|
||||
std::set<ComponentType> AddPlugin(const std::string& path, const std::string& libname, bool saveWithScene = false);
|
||||
|
||||
/// Retrieves the names of the currently loaded plugins (with no path and no extension)
|
||||
const std::map<std::string, bool>& GetLoadedPlugins() const { return mLoadedPlugins; }
|
||||
|
||||
PluginFactoryMap& GetFactories() { return mFactories; }
|
||||
|
||||
// get extension appended to lib name to point to shared library name
|
||||
static std::string GetLibExtension();
|
||||
|
||||
// get library file name from plugin name, platform dependent
|
||||
std::string GetSharedLibNameFromPluginName(const std::string& pluginName);
|
||||
|
||||
private:
|
||||
|
||||
/** Get PluginFactory for Plugin with this name.
|
||||
* @param name The name of the Plugin/PluginFactory to get
|
||||
*/
|
||||
ComponentPluginFactory* GetPluginFactory(ComponentType ctype);
|
||||
|
||||
/** load all plugin factories from libraries found in path */
|
||||
void LoadPluginFactories(const std::string& pluginname, const std::string& path, std::list<ComponentPluginFactory*>& factories);
|
||||
|
||||
/** map from plugin name -> plugin factory */
|
||||
PluginFactoryMap mFactories;
|
||||
|
||||
/// List of libraries (plugins) currently loaded
|
||||
/**
|
||||
* We assume the library name is the same as the file name, with
|
||||
* no path nor extension. We therefore just store the library name
|
||||
*
|
||||
The map stores each name with a flag that indicates if the library must be saved to
|
||||
scene. It is up to the code filling this list to decide what libs must go to file.
|
||||
*/
|
||||
std::map<std::string, bool> mLoadedPlugins;
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
|
||||
#define DTE_EXPORT_MACRO __declspec(dllexport)
|
||||
#else
|
||||
#define DTE_EXPORT_MACRO
|
||||
#endif
|
||||
|
||||
#define REGISTER_DTENTITYPLUGIN(pluginname, count, ...) \
|
||||
extern "C" DTE_EXPORT_MACRO void dtEntity_##pluginname(std::list<dtEntity::ComponentPluginFactory*>& list) \
|
||||
{dtEntity::AddToList(list, count, __VA_ARGS__);} \
|
||||
|
||||
struct DT_ENTITY_EXPORT PluginFunctionProxy
|
||||
{
|
||||
PluginFunctionProxy(CreatePluginFactoriesFn plgfunction, RegisterMessagesFn msgfunction) ;
|
||||
};
|
||||
}
|
||||
|
||||
#if DTENTITY_LIBRARY_STATIC
|
||||
|
||||
#define USE_DTENTITYPLUGIN(pluginname) \
|
||||
extern "C" void dtEntity_##pluginname(std::list<dtEntity::ComponentPluginFactory*>&); \
|
||||
extern "C" void dtEntityMessages_##pluginname(dtEntity::MessageFactory& mf); \
|
||||
static dtEntity::PluginFunctionProxy proxy_##pluginname(dtEntity_##pluginname, dtEntityMessages_##pluginname);
|
||||
|
||||
#else
|
||||
#define USE_DTENTITYPLUGIN(pluginname)
|
||||
#endif
|
||||
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
class DebugDrawInterface;
|
||||
DT_ENTITY_EXPORT void SetDebugDrawInterface(DebugDrawInterface*);
|
||||
DT_ENTITY_EXPORT DebugDrawInterface* GetDebugDrawInterface();
|
||||
|
||||
class InputInterface;
|
||||
DT_ENTITY_EXPORT void SetInputInterface(InputInterface*);
|
||||
DT_ENTITY_EXPORT InputInterface* GetInputInterface();
|
||||
|
||||
class SystemInterface;
|
||||
DT_ENTITY_EXPORT void SetSystemInterface(SystemInterface*);
|
||||
DT_ENTITY_EXPORT SystemInterface* GetSystemInterface();
|
||||
|
||||
class WindowInterface;
|
||||
DT_ENTITY_EXPORT void SetWindowInterface(WindowInterface*);
|
||||
DT_ENTITY_EXPORT WindowInterface* GetWindowInterface();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/property.h>
|
||||
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* Can be used to add simple debug geometry to the scene. Each debug graphics primitive is added
|
||||
* together with a lifetime / duration.
|
||||
* If you want to do per-frame drawing, simply set a duration of 0 and
|
||||
* execute the draw each frame.
|
||||
* Warning: To use, first do SetEnabled(true), it is off by default!
|
||||
*/
|
||||
class DebugDrawInterface
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~DebugDrawInterface() {}
|
||||
|
||||
/**
|
||||
* Draw a single point
|
||||
* @param position Draw point here
|
||||
* @param color Draw with this color
|
||||
* @param size Size of points in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddPoint(const Vec3f& position, const Vec4f& color, int size = 1,
|
||||
float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw multiple points
|
||||
* @param positions A vector of point positions
|
||||
* @param color Draw with this color
|
||||
* @param size Size of points in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddPoints(const std::vector<Vec3f>& positions, const Vec4f& color,
|
||||
int size = 1, float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw a single line
|
||||
* @param start Line starts here
|
||||
* @param end Line ends here
|
||||
* @param color Draw with this color
|
||||
* @param linewidth Width of line in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddLine(const Vec3f& start, const Vec3f& end, const Vec4f& color,
|
||||
int linewidth = 1, float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw a number of lines
|
||||
* @param lines A vector containing two entries for each line. So to draw two lines you have to have four entries.
|
||||
* @param color Draw with this color
|
||||
* @param linewidth Width of line in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddLines(const std::vector<Vec3f>& lines, const Vec4f& color,
|
||||
int linewidth = 1, float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw a 3d cross
|
||||
* @param position Draw point here
|
||||
* @param color Draw with this color
|
||||
* @param size length of each arm
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddCross(const Vec3f& position, const Vec4f& color, float size,
|
||||
float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw a sphere
|
||||
* @param position Draw sphere here
|
||||
* @param radius radius of sphere
|
||||
* @param color Draw with this color
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddSphere(const Vec3f& position, float radius, const Vec4f& color,
|
||||
float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw a single triangle
|
||||
* @param vert0 First vertex of triangle
|
||||
* @param vert1 Second vertex of triangle
|
||||
* @param vert2 Third vertex of triangle
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddTriangle(const Vec3f& vert0, const Vec3f& vert1,
|
||||
const Vec3f& vert2, const Vec4f& color, int lineWidth,
|
||||
float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw multiple triangles
|
||||
* @param verts A vector containing triangle verts. The vector should contain three entries for each triangle.
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddTriangles(const std::vector<Vec3f>& verts,
|
||||
const Vec4f& color, int lineWidth, float duration = 0,
|
||||
bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw a circle
|
||||
* @param position Center of circle is here
|
||||
* @param planeNormal A normal vector pointing away from the face of the disk
|
||||
* @param radius Radius of disk
|
||||
* @param color Draw with this color
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddCircle(const Vec3f& position, const Vec3f& planeNormal,
|
||||
float radius, const Vec4f& color, float duration = 0,
|
||||
bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw a text string
|
||||
* @param position Draw text here
|
||||
* @param str The text to draw
|
||||
* @param color Draw with this color
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddString(const Vec3f& position, const std::string& str,
|
||||
const Vec4f& color, float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Draw an axis aligned bounding box
|
||||
* @param minCoords start box from here
|
||||
* @param maxCoords end box here
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddAABB(const Vec3f& minCoords, const Vec3f& maxCoords,
|
||||
const Vec4f& color, int lineWidth, float duration = 0,
|
||||
bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Add an oriented bounding box
|
||||
* @param matrix transformation matrix to apply to box
|
||||
* @param minCoords start box from here
|
||||
* @param maxCoords end box here
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddOBB(const Matrix& matrix, const Vec3f& minCoords,
|
||||
const Vec3f& maxCoords, const Vec4f& color, int lineWidth,
|
||||
float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
/**
|
||||
* Add a cross showing coordinate orientation
|
||||
* @param matrix transformation cross by this matrix
|
||||
* @param color Draw with this color
|
||||
* @param size length of cross arms
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
virtual void AddAxes(const Matrix& matrix, const Vec4f& color,
|
||||
float size, float duration = 0, bool depthTestEnabled = true) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* DebugDrawInterface is disabled by default, enable it!
|
||||
*/
|
||||
virtual void SetEnabled(bool enabled) = 0;
|
||||
virtual bool IsEnabled() const = 0;
|
||||
|
||||
/**
|
||||
* Immediately remove all debug geometry
|
||||
*/
|
||||
virtual void Clear() = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,335 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
|
||||
#include <dtEntity/entity.h>
|
||||
#include <dtEntity/entitysystem.h>
|
||||
#include <dtEntity/dtentity_config.h>
|
||||
|
||||
#include <dtEntity/entitymanager.h>
|
||||
#include <dtEntity/log.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if USE_BOOST_POOL
|
||||
#include <boost/pool/object_pool.hpp>
|
||||
#include <boost/pool/pool.hpp>
|
||||
#endif
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
class ComponentStoreMap
|
||||
: public std::unordered_map<EntityId, T*>
|
||||
{
|
||||
public:
|
||||
typedef typename std::unordered_map<EntityId, T*>::size_type size_type;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
struct MemAllocPolicyNew
|
||||
{
|
||||
static T* Create()
|
||||
{
|
||||
return new T;
|
||||
}
|
||||
|
||||
static void Destroy(T* t)
|
||||
{
|
||||
delete t;
|
||||
}
|
||||
|
||||
static void DestroyAll(ComponentStoreMap<T>& components)
|
||||
{
|
||||
for(typename ComponentStoreMap<T>::iterator i = components.begin(); i != components.end(); ++i)
|
||||
{
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
~MemAllocPolicyNew() {}
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#if USE_BOOST_POOL
|
||||
template<class T>
|
||||
struct MemAllocPolicyBoostPool
|
||||
{
|
||||
static T* Create()
|
||||
{
|
||||
return mComponentPool->construct();
|
||||
}
|
||||
|
||||
static void Destroy(T* t)
|
||||
{
|
||||
mComponentPool->destroy(t);
|
||||
}
|
||||
|
||||
static void DestroyAll(ComponentStoreMap<T>& components)
|
||||
{
|
||||
delete mComponentPool;
|
||||
}
|
||||
|
||||
protected:
|
||||
~MemAllocPolicyBoostPool() {}
|
||||
|
||||
private:
|
||||
boost::object_pool<T>* mComponentPool;
|
||||
};
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* A simple base for an entity system that handles component allocation
|
||||
* and deletion.
|
||||
* Uses an unordered map for component storage
|
||||
*/
|
||||
template<typename T, template<class> class MemAllocPolicy = MemAllocPolicyNew>
|
||||
class DefaultEntitySystem
|
||||
: public EntitySystem
|
||||
, public MemAllocPolicy<T>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ComponentStoreMap<T> ComponentStore;
|
||||
typedef typename ComponentStoreMap<T>::size_type size_type;
|
||||
|
||||
DefaultEntitySystem(EntityManager& em, ComponentType baseType = StringId())
|
||||
: EntitySystem(em, baseType)
|
||||
, mComponentType(T::TYPE)
|
||||
{
|
||||
}
|
||||
|
||||
~DefaultEntitySystem()
|
||||
{
|
||||
MemAllocPolicy<T>::DestroyAll(mComponents);
|
||||
}
|
||||
|
||||
virtual ComponentType GetComponentType() const;
|
||||
|
||||
virtual bool HasComponent(EntityId eid) const;
|
||||
|
||||
T* GetComponent(EntityId eid);
|
||||
const T* GetComponent(EntityId eid) const;
|
||||
|
||||
virtual bool GetComponent(EntityId eid, Component*& c);
|
||||
virtual bool GetComponent(EntityId eid, const Component*& c) const;
|
||||
|
||||
virtual bool CreateComponent(EntityId eid, Component*& component);
|
||||
virtual bool DeleteComponent(EntityId eid);
|
||||
|
||||
virtual void GetEntitiesInSystem(std::list<EntityId>& toFill) const;
|
||||
|
||||
size_type GetNumComponents() const;
|
||||
|
||||
virtual GroupProperty GetComponentProperties() const;
|
||||
|
||||
typename ComponentStore::iterator begin();
|
||||
typename ComponentStore::const_iterator begin() const;
|
||||
|
||||
typename ComponentStore::iterator end();
|
||||
typename ComponentStore::const_iterator end() const;
|
||||
|
||||
protected:
|
||||
|
||||
ComponentStore mComponents;
|
||||
ComponentType mComponentType;
|
||||
};
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
ComponentType DefaultEntitySystem<T, MemAllocPolicy>::GetComponentType() const
|
||||
{
|
||||
return mComponentType;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
bool DefaultEntitySystem<T, MemAllocPolicy>::HasComponent(EntityId eid) const
|
||||
{
|
||||
typename ComponentStore::const_iterator i = mComponents.find(eid);
|
||||
return(i != mComponents.end());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
T* DefaultEntitySystem<T, MemAllocPolicy>::GetComponent(EntityId eid)
|
||||
{
|
||||
typename ComponentStore::iterator i = mComponents.find(eid);
|
||||
if(i != mComponents.end())
|
||||
{
|
||||
return i->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
const T* DefaultEntitySystem<T, MemAllocPolicy>::GetComponent(EntityId eid) const
|
||||
{
|
||||
typename ComponentStore::const_iterator i = mComponents.find(eid);
|
||||
if(i != mComponents.end())
|
||||
{
|
||||
return i->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
bool DefaultEntitySystem<T, MemAllocPolicy>::GetComponent(EntityId eid, Component*& c)
|
||||
{
|
||||
typename ComponentStore::iterator i = mComponents.find(eid);
|
||||
if(i != mComponents.end())
|
||||
{
|
||||
c = i->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
bool DefaultEntitySystem<T, MemAllocPolicy>::GetComponent(EntityId eid, const Component*& c) const
|
||||
{
|
||||
typename ComponentStore::const_iterator i = mComponents.find(eid);
|
||||
if(i != mComponents.end())
|
||||
{
|
||||
c = i->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
bool DefaultEntitySystem<T, MemAllocPolicy>::CreateComponent(EntityId eid, Component*& component)
|
||||
{
|
||||
if(HasComponent(eid))
|
||||
{
|
||||
LOG_ERROR("Could not create component: already exists!");
|
||||
return false;
|
||||
}
|
||||
|
||||
T* t = MemAllocPolicy<T>::Create();
|
||||
|
||||
if(t == NULL)
|
||||
{
|
||||
LOG_ERROR("Out of memory!");
|
||||
return false;
|
||||
}
|
||||
component = t;
|
||||
mComponents[eid] = t;
|
||||
|
||||
Entity* e;
|
||||
bool found = GetEntityManager().GetEntity(eid, e);
|
||||
if(!found)
|
||||
{
|
||||
LOG_ERROR("Can't add component to entity: entity does not exist!");
|
||||
return false;
|
||||
}
|
||||
component->OnAddedToEntity(*e);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
bool DefaultEntitySystem<T, MemAllocPolicy>::DeleteComponent(EntityId eid)
|
||||
{
|
||||
typename ComponentStore::iterator i = mComponents.find(eid);
|
||||
if(i == mComponents.end())
|
||||
return false;
|
||||
T* component = i->second;
|
||||
Entity* e;
|
||||
bool found = GetEntityManager().GetEntity(eid, e);
|
||||
assert(found);
|
||||
component->OnRemovedFromEntity(*e);
|
||||
mComponents.erase(i);
|
||||
MemAllocPolicy<T>::Destroy(component);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
void DefaultEntitySystem<T, MemAllocPolicy>::GetEntitiesInSystem(std::list<EntityId>& toFill) const
|
||||
{
|
||||
typename ComponentStore::const_iterator i = mComponents.begin();
|
||||
for(;i != mComponents.end(); ++i)
|
||||
{
|
||||
toFill.push_back(i->first);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
typename DefaultEntitySystem<T, MemAllocPolicy>::size_type DefaultEntitySystem<T, MemAllocPolicy>::GetNumComponents() const
|
||||
{
|
||||
return mComponents.size();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
GroupProperty DefaultEntitySystem<T, MemAllocPolicy>::GetComponentProperties() const
|
||||
{
|
||||
T t;
|
||||
return t;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
typename ComponentStoreMap<T>::iterator DefaultEntitySystem<T, MemAllocPolicy>::begin()
|
||||
{
|
||||
return mComponents.begin();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
typename ComponentStoreMap<T>::const_iterator DefaultEntitySystem<T, MemAllocPolicy>::begin() const
|
||||
{
|
||||
return mComponents.begin();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
typename ComponentStoreMap<T>::iterator DefaultEntitySystem<T, MemAllocPolicy>::end()
|
||||
{
|
||||
return mComponents.end();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T, template<class> class MemAllocPolicy>
|
||||
typename ComponentStoreMap<T>::const_iterator DefaultEntitySystem<T, MemAllocPolicy>::end() const
|
||||
{
|
||||
return mComponents.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
// auto-generated by CMake, do not edit!
|
||||
|
||||
#define DTENTITY_VERSION_MAJOR 0
|
||||
#define DTENTITY_VERSION_MINOR 1
|
||||
#define DTENTITY_VERSION_PATCH 1
|
||||
|
||||
// build entity systems for sound support?
|
||||
#define BUILD_OPENAL 0
|
||||
|
||||
// should boost::pool be used for memory allocations of components?
|
||||
#define USE_BOOST_POOL 0
|
||||
|
||||
// build dtEntity and its libs as static libraries?
|
||||
#define DTENTITY_LIBRARY_STATIC 0
|
||||
|
||||
// use strings instead of hash values?
|
||||
#define DTENTITY_USE_STRINGS_AS_STRINGIDS 0
|
||||
|
||||
// was google protocol buffers found by cmake?
|
||||
#define PROTOBUF_FOUND 0
|
||||
|
||||
// was enet found by cmake?
|
||||
#define ENET_FOUND 0
|
||||
|
||||
// should dtEntity call OnPropertyChanged() method when a property of a component
|
||||
// was changed? For backwards compability only
|
||||
#define CALL_ONPROPERTYCHANGED_METHOD 1
|
||||
|
||||
// Should message calls be profiled?
|
||||
#define DTENTITY_PROFILING_ENABLED 0
|
||||
@@ -0,0 +1,628 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/FastDelegate.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicArrayProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<const PropertyArray&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<PropertyArray> GetValueCB;
|
||||
|
||||
DynamicArrayProperty() {}
|
||||
|
||||
DynamicArrayProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::ARRAY; }
|
||||
|
||||
virtual PropertyArray ArrayValue() const { return mGetValueCallback(); }
|
||||
virtual void SetArray(const PropertyArray& v) { Set(v); }
|
||||
|
||||
virtual const std::string StringValue() const { ArrayProperty p(Get()); return p.StringValue(); }
|
||||
virtual void SetString(const std::string& v) { ArrayProperty p; p.SetString(v); Set(p.Get());}
|
||||
PropertyArray Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new ArrayProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.ArrayValue() == Get(); }
|
||||
void Set(const PropertyArray& v) { mSetValueCallback(v); }
|
||||
virtual bool SetFrom(const Property& other) { Set(other.ArrayValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicBoolProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<bool, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<bool> GetValueCB;
|
||||
|
||||
DynamicBoolProperty() {}
|
||||
|
||||
DynamicBoolProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::BOOL; }
|
||||
|
||||
virtual bool BoolValue() const { return mGetValueCallback(); }
|
||||
virtual void SetBool(bool v) { Set(v); }
|
||||
|
||||
virtual const std::string StringValue() const { BoolProperty p(Get()); return p.StringValue(); }
|
||||
virtual void SetString(const std::string& v) { BoolProperty p; p.SetString(v); Set(p.Get());}
|
||||
bool Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new BoolProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.BoolValue() == Get(); }
|
||||
void Set(bool v) { mSetValueCallback(v); }
|
||||
virtual bool SetFrom(const Property& other) { Set(other.BoolValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicDoubleProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<double, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<double> GetValueCB;
|
||||
|
||||
DynamicDoubleProperty() {}
|
||||
|
||||
DynamicDoubleProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::DOUBLE; }
|
||||
|
||||
virtual double DoubleValue() const { return mGetValueCallback(); }
|
||||
virtual void SetDouble(double v) { Set(v); }
|
||||
|
||||
virtual const std::string StringValue() const { DoubleProperty p(Get()); return p.StringValue(); }
|
||||
virtual void SetString(const std::string& v) { DoubleProperty p; p.SetString(v); Set(p.Get());}
|
||||
double Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new DoubleProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.DoubleValue() == Get(); }
|
||||
void Set(double v) { mSetValueCallback(v); }
|
||||
virtual bool SetFrom(const Property& other) { Set(other.DoubleValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicFloatProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<float, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<float> GetValueCB;
|
||||
|
||||
DynamicFloatProperty() {}
|
||||
|
||||
DynamicFloatProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::FLOAT; }
|
||||
|
||||
virtual float FloatValue() const { return mGetValueCallback(); }
|
||||
virtual void SetFloat(float v) { Set(v); }
|
||||
|
||||
virtual const std::string StringValue() const { FloatProperty p(Get()); return p.StringValue(); }
|
||||
virtual void SetString(const std::string& v) { FloatProperty p; p.SetString(v); Set(p.Get());}
|
||||
float Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new FloatProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.FloatValue() == Get(); }
|
||||
void Set(float v) { mSetValueCallback(v); }
|
||||
virtual bool SetFrom(const Property& other) { Set(other.FloatValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicGroupProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<const PropertyGroup&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<PropertyGroup> GetValueCB;
|
||||
|
||||
DynamicGroupProperty() {}
|
||||
|
||||
DynamicGroupProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::GROUP; }
|
||||
|
||||
virtual PropertyGroup GroupValue() const { return mGetValueCallback(); }
|
||||
virtual void SetGroup(const PropertyGroup& v) { Set(v); }
|
||||
|
||||
virtual const std::string StringValue() const { GroupProperty p(Get()); return p.StringValue(); }
|
||||
virtual void SetString(const std::string& v) { GroupProperty p; p.SetString(v); Set(p.Get());}
|
||||
PropertyGroup Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new GroupProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.GroupValue() == Get(); }
|
||||
void Set(const PropertyGroup& v) { mSetValueCallback(v); }
|
||||
virtual bool SetFrom(const Property& other) { Set(other.GroupValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicIntProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<int, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<int> GetValueCB;
|
||||
|
||||
DynamicIntProperty() {}
|
||||
|
||||
DynamicIntProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::INT; }
|
||||
|
||||
virtual int IntValue() const { return mGetValueCallback(); }
|
||||
virtual void SetInt(int v) { Set(v); }
|
||||
|
||||
virtual const std::string StringValue() const { IntProperty p(Get()); return p.StringValue(); }
|
||||
virtual void SetString(const std::string& v) { IntProperty p; p.SetString(v); Set(p.Get());}
|
||||
int Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new IntProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.IntValue() == Get(); }
|
||||
void Set(int v) { mSetValueCallback(v); }
|
||||
virtual bool SetFrom(const Property& other) { Set(other.IntValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicStringProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1< const std::string&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<std::string> GetValueCB;
|
||||
|
||||
DynamicStringProperty() {}
|
||||
|
||||
DynamicStringProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::STRING; }
|
||||
|
||||
virtual const std::string StringValue() const { return mGetValueCallback(); }
|
||||
virtual StringId StringIdValue() const { return dtEntity::SIDHash(StringValue()); }
|
||||
//virtual void SetStringId(dtEntity::StringId v) { Set(GetStringFromSID(v)); }
|
||||
|
||||
const std::string Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new StringProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.StringValue() == Get(); }
|
||||
void Set(const std::string& v) { mSetValueCallback(v); }
|
||||
virtual void SetString(const std::string& v) { Set(v); }
|
||||
virtual bool SetFrom(const Property& other) { Set(other.StringValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicStringIdProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<StringId, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<StringId> GetValueCB;
|
||||
|
||||
DynamicStringIdProperty() {}
|
||||
|
||||
DynamicStringIdProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::STRINGID; }
|
||||
|
||||
virtual StringId StringIdValue() const { return mGetValueCallback(); }
|
||||
virtual void SetStringId(StringId v) { Set(v); }
|
||||
|
||||
virtual const std::string StringValue() const { StringIdProperty p(Get()); return p.StringValue(); }
|
||||
virtual void SetString(const std::string& v) { StringIdProperty p; p.SetString(v); Set(p.Get());}
|
||||
StringId Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new StringIdProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.StringIdValue() == Get(); }
|
||||
void Set(StringId v) { mSetValueCallback(v); }
|
||||
virtual bool SetFrom(const Property& other) { Set(other.StringIdValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicUIntProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<unsigned int, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<unsigned int> GetValueCB;
|
||||
|
||||
DynamicUIntProperty() {}
|
||||
|
||||
DynamicUIntProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::UINT; }
|
||||
|
||||
virtual unsigned int UIntValue() const { return mGetValueCallback(); }
|
||||
virtual void SetUInt(unsigned int v) { Set(v); }
|
||||
|
||||
virtual const std::string StringValue() const { UIntProperty p(Get()); return p.StringValue(); }
|
||||
virtual void SetString(const std::string& v) { UIntProperty p; p.SetString(v); Set(p.Get());}
|
||||
unsigned int Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new UIntProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.UIntValue() == Get(); }
|
||||
void Set(unsigned int v) { mSetValueCallback(v); }
|
||||
virtual bool SetFrom(const Property& other) { Set(other.UIntValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicVec2dProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1< const Vec2d&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<Vec2d> GetValueCB;
|
||||
|
||||
DynamicVec2dProperty() {}
|
||||
|
||||
DynamicVec2dProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::VEC2D; }
|
||||
|
||||
virtual Vec2f Vec2Value() const { return Get(); }
|
||||
virtual void SetVec2(const Vec2f& v) { Set(v); }
|
||||
virtual Vec2d Vec2dValue() const { return Get(); }
|
||||
virtual void SetVec2D(const Vec2d& v) { Set(v); }
|
||||
virtual const std::string StringValue() const { Vec2dProperty p(Get()); return p.StringValue(); }
|
||||
Vec2d Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new Vec2dProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.Vec2dValue() == Get(); }
|
||||
void Set(const Vec2d& v) { mSetValueCallback(v); }
|
||||
virtual void SetString(const std::string& v) { Vec2dProperty p; p.SetString(v); Set(p.Get());}
|
||||
virtual bool SetFrom(const Property& other) { Set(other.Vec2dValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicVec3dProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1< const Vec3d&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<Vec3d> GetValueCB;
|
||||
|
||||
DynamicVec3dProperty() {}
|
||||
|
||||
DynamicVec3dProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::VEC3D; }
|
||||
|
||||
virtual Vec3f Vec3Value() const { return Get(); }
|
||||
virtual void SetVec3(const Vec3f& v) { Set(v); }
|
||||
virtual Vec3d Vec3dValue() const { return Get(); }
|
||||
virtual void SetVec3D(const Vec3d& v) { Set(v); }
|
||||
virtual const std::string StringValue() const { Vec3dProperty p(Get()); return p.StringValue(); }
|
||||
Vec3d Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new Vec3dProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.Vec3dValue() == Get(); }
|
||||
void Set(const Vec3d& v) { mSetValueCallback(v); }
|
||||
virtual void SetString(const std::string& v) { Vec3dProperty p; p.SetString(v); Set(p.Get());}
|
||||
virtual bool SetFrom(const Property& other) { Set(other.Vec3dValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicVec4dProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1< const Vec4d&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<Vec4d> GetValueCB;
|
||||
|
||||
DynamicVec4dProperty() {}
|
||||
|
||||
DynamicVec4dProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::VEC4D; }
|
||||
|
||||
virtual Vec4f Vec4Value() const { return Get(); }
|
||||
virtual void SetVec4(const Vec4f& v) { Set(v); }
|
||||
virtual Vec4d Vec4dValue() const { return Get(); }
|
||||
virtual void SetVec4D(const Vec4d& v) { Set(v); }
|
||||
virtual const std::string StringValue() const { Vec4dProperty p(Get()); return p.StringValue(); }
|
||||
Vec4d Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new Vec4dProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.Vec4dValue() == Get(); }
|
||||
void Set(const Vec4d& v) { mSetValueCallback(v); }
|
||||
virtual void SetString(const std::string& v) { Vec4dProperty p; p.SetString(v); Set(p.Get());}
|
||||
virtual bool SetFrom(const Property& other) { Set(other.Vec4dValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicVec2Property : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<const Vec2f&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<Vec2f> GetValueCB;
|
||||
|
||||
DynamicVec2Property() {}
|
||||
|
||||
DynamicVec2Property(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::VEC2; }
|
||||
|
||||
virtual Vec2f Vec2Value() const { return Get(); }
|
||||
virtual void SetVec2(const Vec2f& v) { Set(v); }
|
||||
virtual Vec2d Vec2dValue() const { return Get(); }
|
||||
virtual void SetVec2D(const Vec2d& v) { Set(v); }
|
||||
virtual const std::string StringValue() const { Vec2Property p(Get()); return p.StringValue(); }
|
||||
Vec2f Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new Vec2Property(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.Vec2Value() == Get(); }
|
||||
void Set(const Vec2f& v) { mSetValueCallback(v); }
|
||||
virtual void SetString(const std::string& v) { Vec2Property p; p.SetString(v); Set(p.Get());}
|
||||
virtual bool SetFrom(const Property& other) { Set(other.Vec2Value()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicVec3Property : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1< const Vec3f&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<Vec3f> GetValueCB;
|
||||
|
||||
DynamicVec3Property() {}
|
||||
|
||||
DynamicVec3Property(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::VEC3; }
|
||||
|
||||
virtual Vec3f Vec3Value() const { return Get(); }
|
||||
virtual void SetVec3(const Vec3f& v) { Set(v); }
|
||||
virtual Vec3d Vec3dValue() const { return Get(); }
|
||||
virtual void SetVec3D(const Vec3d& v) { Set(v); }
|
||||
virtual const std::string StringValue() const { Vec3Property p(Get()); return p.StringValue(); }
|
||||
Vec3f Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new Vec3Property(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.Vec3Value() == Get(); }
|
||||
void Set(const Vec3f& v) { mSetValueCallback(v); }
|
||||
virtual void SetString(const std::string& v) { Vec3Property p; p.SetString(v); Set(p.Get());}
|
||||
virtual bool SetFrom(const Property& other) { Set(other.Vec3Value()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicVec4Property : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1< const Vec4f&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<Vec4f> GetValueCB;
|
||||
|
||||
DynamicVec4Property() {}
|
||||
|
||||
DynamicVec4Property(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::VEC4; }
|
||||
|
||||
virtual Vec4f Vec4Value() const { return Get(); }
|
||||
virtual void SetVec4(const Vec4f& v) { Set(v); }
|
||||
virtual Vec4d Vec4dValue() const { return Get(); }
|
||||
virtual void SetVec4D(const Vec4d& v) { Set(v); }
|
||||
virtual const std::string StringValue() const { Vec4Property p(Get()); return p.StringValue(); }
|
||||
Vec4f Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new Vec4Property(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.Vec4Value() == Get(); }
|
||||
void Set(const Vec4f& v) { mSetValueCallback(v); }
|
||||
virtual void SetString(const std::string& v) { Vec4Property p; p.SetString(v); Set(p.Get());}
|
||||
virtual bool SetFrom(const Property& other) { Set(other.Vec4Value()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicQuatProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1< const Quat&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<Quat> GetValueCB;
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::QUAT; }
|
||||
|
||||
DynamicQuatProperty() {}
|
||||
|
||||
DynamicQuatProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual Quat QuatValue() const { return Get(); }
|
||||
virtual void SetQuat(const Quat& v) { Set(v); }
|
||||
virtual const std::string StringValue() const { QuatProperty p(Get()); return p.StringValue(); }
|
||||
Quat Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new QuatProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.QuatValue() == Get(); }
|
||||
void Set(const Quat& v) { mSetValueCallback(v); }
|
||||
virtual void SetString(const std::string& v) { QuatProperty p; p.SetString(v); Set(p.Get());}
|
||||
virtual bool SetFrom(const Property& other) { Set(other.QuatValue()); return true; }
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicMatrixProperty : public Property
|
||||
{
|
||||
public:
|
||||
typedef fastdelegate::FastDelegate1<const Matrix&, void> SetValueCB;
|
||||
typedef fastdelegate::FastDelegate0<Matrix> GetValueCB;
|
||||
|
||||
virtual DataType::e GetDataType() const { return DataType::MATRIX; }
|
||||
|
||||
DynamicMatrixProperty() {}
|
||||
|
||||
DynamicMatrixProperty(const SetValueCB& s, const GetValueCB& g)
|
||||
: mSetValueCallback(s)
|
||||
, mGetValueCallback(g)
|
||||
{
|
||||
}
|
||||
|
||||
virtual Matrix MatrixValue() const { return Get(); }
|
||||
virtual void SetMatrix(const Matrix& v) { Set(v); }
|
||||
virtual const std::string StringValue() const { MatrixProperty p(Get()); return p.StringValue(); }
|
||||
Matrix Get() const { return mGetValueCallback(); }
|
||||
|
||||
virtual Property* Clone() const { return new MatrixProperty(Get()); }
|
||||
virtual bool operator==(const Property& other) const { return other.MatrixValue() == Get(); }
|
||||
void Set(const Matrix& v) { mSetValueCallback(v); }
|
||||
virtual void SetString(const std::string& v) { MatrixProperty p; p.SetString(v); Set(p.Get());}
|
||||
virtual bool SetFrom(const Property& other) { Set(other.MatrixValue()); return true;}
|
||||
|
||||
private:
|
||||
|
||||
SetValueCB mSetValueCallback;
|
||||
GetValueCB mGetValueCallback;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT DynamicsComponent
|
||||
: public Component
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Component BaseClass;
|
||||
|
||||
static const ComponentType TYPE;
|
||||
static const StringId VelocityId;
|
||||
static const StringId AngularVelocityId;
|
||||
static const StringId AccelerationId;
|
||||
|
||||
DynamicsComponent();
|
||||
virtual ~DynamicsComponent();
|
||||
|
||||
virtual ComponentType GetType() const { return TYPE; }
|
||||
|
||||
void OnAddedToEntity(Entity &entity) { mEntity = &entity; }
|
||||
|
||||
Vec3f GetVelocity() const { return mVelocityVal; }
|
||||
void SetVelocity(const Vec3f& v);
|
||||
|
||||
const Quat& GetAngularVelocity() const { return mAngularVelocity.GetAsQuat(); }
|
||||
void SetAngularVelocity(const Quat& v) { mAngularVelocity.Set(v); }
|
||||
|
||||
const Vec3f& GetAcceleration() const { return mAcceleration.GetAsVec3(); }
|
||||
void SetAcceleration(const Vec3f& v) { mAcceleration.Set(v); }
|
||||
|
||||
protected:
|
||||
Entity* mEntity;
|
||||
|
||||
// path to loaded script file
|
||||
DynamicVec3Property mVelocity;
|
||||
Vec3f mVelocityVal;
|
||||
QuatProperty mAngularVelocity;
|
||||
Vec3Property mAcceleration;
|
||||
bool mIsMoving;
|
||||
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DT_ENTITY_EXPORT DynamicsSystem
|
||||
: public DefaultEntitySystem<DynamicsComponent>
|
||||
{
|
||||
public:
|
||||
|
||||
static const ComponentType TYPE;
|
||||
|
||||
DynamicsSystem(EntityManager& em);
|
||||
~DynamicsSystem();
|
||||
|
||||
};
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <dtEntity/entitymanager.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <vector>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* The entity class is simply a convenience class to bundle
|
||||
* the entity ID and access to the entity manager.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT Entity
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param em The entity manager that holds this entity
|
||||
* @param id The unique ID of this entity
|
||||
*/
|
||||
Entity(EntityManager& em, EntityId id);
|
||||
|
||||
/**
|
||||
* Create a component of given type and assign it to component
|
||||
* @param t Type of component to construct
|
||||
* @param component Receives newly constructed component
|
||||
* @return true if success
|
||||
*/
|
||||
bool CreateComponent(ComponentType t, Component*& component);
|
||||
|
||||
// templated version
|
||||
template<typename T>
|
||||
bool CreateComponent(T*& component);
|
||||
|
||||
/**
|
||||
* Get component from this entity
|
||||
* @param component receives the component if found
|
||||
* @param searchDerived Return components of derived typs if found
|
||||
* @return true if found
|
||||
*/
|
||||
template<typename T>
|
||||
bool GetComponent(T*& component, bool searchDerived = false) const;
|
||||
|
||||
/**
|
||||
* Get component from this entity
|
||||
* @param component receives the component if found
|
||||
* @param searchDerived Return components of derived typs if found
|
||||
* @return true if found
|
||||
*/
|
||||
bool GetComponent(ComponentType t, Component*& component, bool searchDerived = false) const;
|
||||
|
||||
/**
|
||||
* Get a list of all component associated with this entity
|
||||
* @param toFill receives the components
|
||||
*/
|
||||
void GetComponents(std::vector<Component*>& toFill);
|
||||
void GetComponents(std::vector<const Component*>& toFill) const;
|
||||
|
||||
/**
|
||||
* @return true if a component of this type is assigned to entity
|
||||
*/
|
||||
bool HasComponent(ComponentType t) const;
|
||||
|
||||
/**
|
||||
* get unique identifier of this entity
|
||||
*/
|
||||
EntityId GetId() const;
|
||||
|
||||
/**
|
||||
* @return the entity manager this entity is assigned to
|
||||
*/
|
||||
EntityManager& GetEntityManager() const;
|
||||
|
||||
private:
|
||||
|
||||
// internal ID
|
||||
EntityId mId;
|
||||
|
||||
// The entity manager that holds this entity
|
||||
EntityManager* mEntityManager;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool Entity::CreateComponent(T*& component)
|
||||
{
|
||||
Component* c;
|
||||
bool success = CreateComponent(T::TYPE, c);
|
||||
if (success)
|
||||
component = static_cast<T*>(c);
|
||||
else
|
||||
component = nullptr;
|
||||
return success;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Entity::GetComponent(T*& component, bool derived) const
|
||||
{
|
||||
return GetEntityManager().GetComponent<T>(this->GetId(), component, derived);
|
||||
}
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
// serial ID for entities
|
||||
typedef unsigned int EntityId;
|
||||
}
|
||||
+421
@@ -0,0 +1,421 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/messagepump.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
#include <OpenThreads/ReadWriteMutex>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class Component;
|
||||
class Entity;
|
||||
class EntitySystem;
|
||||
class Message;
|
||||
|
||||
/**
|
||||
* Entity manager is a container for entity systems.
|
||||
* Each entity system holds entity components of a specific type.
|
||||
* The entity manager gives access to the entity systems and can be used to
|
||||
* create, retrieve and delete components.
|
||||
*
|
||||
* Also, Entity manager is a central point to send and register to messages.
|
||||
* Messages can be sent (emitted) immediately to all registrants, or they can be
|
||||
* posted to a message queue to be emitted at a later time.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntityManager
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param startEntitySystems if true, start default entity
|
||||
* systems like OSG components etc
|
||||
*/
|
||||
EntityManager();
|
||||
|
||||
// Destructor
|
||||
~EntityManager();
|
||||
|
||||
/**
|
||||
* can be used to clean up wrappers for components or
|
||||
* execute other actions
|
||||
*/
|
||||
class ComponentDeletedCallback
|
||||
{
|
||||
public:
|
||||
virtual void ComponentDeleted(ComponentType t, EntityId id) = 0;
|
||||
virtual ~ComponentDeletedCallback() {}
|
||||
};
|
||||
|
||||
typedef std::vector<ComponentDeletedCallback*> ComponentDeletedCallbacks;
|
||||
|
||||
|
||||
/**
|
||||
* If user executes CreateComponent and no entity system with given component
|
||||
* type is registered then all EntitySystemRequestCallbacks are executed
|
||||
* until one returns true. Callback can be used to add entity systems lazily.
|
||||
*/
|
||||
class EntitySystemRequestCallback
|
||||
{
|
||||
public:
|
||||
virtual bool CreateEntitySystem(EntityManager* em, ComponentType t) = 0;
|
||||
|
||||
virtual ~EntitySystemRequestCallback() {}
|
||||
};
|
||||
|
||||
typedef std::vector<EntitySystemRequestCallback*> EntitySystemRequestCallbacks;
|
||||
|
||||
/**
|
||||
* Get entity object for entity ID.
|
||||
* @param id Unique id of the entity to retrieve
|
||||
* @param entity Will receive pointer to entity object
|
||||
* @return true if entity with this id was found
|
||||
* @threadsafe
|
||||
*/
|
||||
bool GetEntity(EntityId id, Entity*& entity);
|
||||
|
||||
/**
|
||||
* return true if entity with this ID exists
|
||||
*/
|
||||
bool EntityExists(EntityId id) const;
|
||||
|
||||
/**
|
||||
* Fill vector with entity ids of all existing entities
|
||||
*/
|
||||
void GetEntityIds(std::vector<EntityId>& toFill);
|
||||
|
||||
/**
|
||||
* delete entity object and tell all entity systems to delete their
|
||||
* components for this entity
|
||||
* @param id id of the entity to delete
|
||||
* @return true if success
|
||||
* @threadsafe
|
||||
*/
|
||||
bool KillEntity(EntityId id);
|
||||
|
||||
/**
|
||||
* Create a new entity with a new unique EntityId
|
||||
* All entities are deleted when entity manager is deleted.
|
||||
* This method is thread safe so that entities can be created from
|
||||
* worker threads. Creation and deletion of entities are
|
||||
* thread-safe, all other entity system/component methods are
|
||||
* non-tread safe.
|
||||
* @param entity Receives pointer to newly created entity
|
||||
* @return true if success
|
||||
* @threadsafe
|
||||
*/
|
||||
bool CreateEntity(Entity*& entity);
|
||||
|
||||
/**
|
||||
* Loops through all components of origin and creates them on target entity
|
||||
* @param target ID of an existing entity with no components
|
||||
* @param origin Clone components of this entity
|
||||
* @return true if success
|
||||
*/
|
||||
bool CloneEntity(EntityId target, EntityId origin);
|
||||
|
||||
/**
|
||||
* @param id Check if an entity with this id exists
|
||||
* @return true if such an entity exists
|
||||
*/
|
||||
bool HasEntity(EntityId id) const;
|
||||
|
||||
/**
|
||||
* returns true while at least one entity exists
|
||||
*/
|
||||
bool HasEntities() const;
|
||||
|
||||
/**
|
||||
* DEPRECATED! Use MapSystem::AddToScene
|
||||
*/
|
||||
bool AddToScene(EntityId eid);
|
||||
|
||||
/**
|
||||
* DEPRECATED! Use MapSystem::RemoveFromScene
|
||||
*/
|
||||
bool RemoveFromScene(EntityId eid);
|
||||
|
||||
/**
|
||||
* @param id Check if an entity system of this component type is active
|
||||
* @return true if such a system exists
|
||||
*/
|
||||
bool HasEntitySystem(ComponentType id) const;
|
||||
|
||||
/**
|
||||
* @param s Add this entity system to the manager
|
||||
*/
|
||||
bool AddEntitySystem(EntitySystem& s);
|
||||
|
||||
/**
|
||||
* @param s Remove this entity system
|
||||
* @return true if entity system was registered, else false
|
||||
*/
|
||||
bool RemoveEntitySystem(EntitySystem& s);
|
||||
|
||||
/**
|
||||
* Get entity system of given type.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
EntitySystem* GetEntitySystem(ComponentType id) const;
|
||||
|
||||
/**
|
||||
* @param id Get entity system for this component type
|
||||
* @param es receives entity system if found
|
||||
* @return true if entity system was found
|
||||
*/
|
||||
template <typename T>
|
||||
bool GetEntitySystem(ComponentType id, T*& es) const;
|
||||
|
||||
template <typename T>
|
||||
bool GetES(T*& es) const;
|
||||
|
||||
/**
|
||||
* Fill vector with all entity systems registered with
|
||||
* the entity manager
|
||||
*/
|
||||
void GetEntitySystems(std::vector<EntitySystem*>& toFill);
|
||||
void GetEntitySystems(std::vector<const EntitySystem*>& toFill) const;
|
||||
|
||||
/**
|
||||
* @param eid Get component of this entity
|
||||
* @param t Get component with this component type
|
||||
* @param component Receives component if found
|
||||
* @param searchDerived If true, return component that inherits t if one exists. Inheritance
|
||||
* is defined by return value of EntitySystem::GetBaseType
|
||||
* @return true if component was found
|
||||
*/
|
||||
bool GetComponent(EntityId eid, ComponentType t, Component*& component, bool searchDerived = false);
|
||||
|
||||
/**
|
||||
* @param eid Get component of this entity
|
||||
* @param component Receives component of type T if found
|
||||
* @param searchDerived If true, return component that inherits t if one exists. Inheritance
|
||||
* is defined by return value of EntitySystem::GetBaseType
|
||||
* @return true if success
|
||||
*/
|
||||
template <typename T>
|
||||
bool GetComponent(EntityId eid, T*& component, bool searchDerived = false);
|
||||
|
||||
/**
|
||||
* Get all components of given entity
|
||||
* Warning: slow. Iterates over all entity systems.
|
||||
* @param eid Get components of this entity
|
||||
* @param toFill receives components
|
||||
*/
|
||||
void GetComponents(EntityId eid, std::vector<Component*>& toFill);
|
||||
void GetComponents(EntityId eid, std::vector<const Component*>& toFill) const;
|
||||
|
||||
/**
|
||||
* @param eid Check if component exists for this entity
|
||||
* @param t Type of component to check for
|
||||
* @param searchDerived If true, search for component that inherits t. Inheritance
|
||||
* is defined by return value of EntitySystem::GetBaseType
|
||||
* @return true if exists
|
||||
*/
|
||||
bool HasComponent(EntityId eid, ComponentType t, bool searchDerived = false) const;
|
||||
|
||||
/**
|
||||
* Create a component of given type for entity
|
||||
* @param eid Add component to this entity
|
||||
* @param id Add component of this type
|
||||
* @param component Receives newly created component if success
|
||||
* @return true if success
|
||||
*/
|
||||
bool CreateComponent(EntityId eid, ComponentType id, Component*& component);
|
||||
|
||||
/**
|
||||
* Create a component of given type for entity
|
||||
* @param eid Add component to this entity
|
||||
* @param component Receives newly created component of type T if success
|
||||
* @return true if success
|
||||
*/
|
||||
template <typename T>
|
||||
bool CreateComponent(EntityId eid, T*& component);
|
||||
|
||||
/**
|
||||
* Delete component.
|
||||
*/
|
||||
bool DeleteComponent(EntityId eid, Component& component);
|
||||
|
||||
/**
|
||||
* Delete component.
|
||||
*/
|
||||
bool DeleteComponent(EntityId eid, ComponentType componentType);
|
||||
|
||||
/**
|
||||
* @return default message pump for inter-system communication
|
||||
*/
|
||||
MessagePump& GetMessagePump()
|
||||
{
|
||||
return mMessagePump;
|
||||
}
|
||||
|
||||
|
||||
// See messagepump.h for documentation
|
||||
inline void RegisterForMessages(MessageType msgtype, const MessageFunctor& ftr, unsigned int options = FilterOptions::DEFAULT, const std::string& funcname = "")
|
||||
{
|
||||
mMessagePump.RegisterForMessages(msgtype, ftr, options, funcname);
|
||||
}
|
||||
|
||||
// See messagepump.h for documentation
|
||||
inline void RegisterForMessages(MessageType msgtype, const MessageFunctor& ftr, const std::string& funcname)
|
||||
{
|
||||
mMessagePump.RegisterForMessages(msgtype, ftr, FilterOptions::DEFAULT, funcname);
|
||||
}
|
||||
|
||||
// See messagepump.h for documentation
|
||||
inline bool UnregisterForMessages(MessageType msgtype, const MessageFunctor& ftr)
|
||||
{
|
||||
return mMessagePump.UnregisterForMessages(msgtype, ftr);
|
||||
}
|
||||
|
||||
// See messagepump.h for documentation
|
||||
inline void EmitMessage(const Message& msg)
|
||||
{
|
||||
mMessagePump.EmitMessage(msg);
|
||||
}
|
||||
|
||||
// See messagepump.h for documentation
|
||||
inline void EnqueueMessage(const Message& msg, double time = 0)
|
||||
{
|
||||
mMessagePump.EnqueueMessage(msg, time);
|
||||
}
|
||||
|
||||
// See messagepump.h for documentation
|
||||
void EmitQueuedMessages(double simtime)
|
||||
{
|
||||
mMessagePump.EmitQueuedMessages(simtime);
|
||||
}
|
||||
|
||||
void AddDeletedCallback(ComponentDeletedCallback* cb);
|
||||
bool RemoveDeletedCallback(ComponentDeletedCallback* cb);
|
||||
|
||||
void AddEntitySystemRequestCallback(EntitySystemRequestCallback* cb);
|
||||
bool RemoveEntitySystemRequestCallback(EntitySystemRequestCallback* cb);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Returns next id and increments internal counter
|
||||
EntityId GetNextAvailableID();
|
||||
|
||||
unsigned int mNextAvailableId;
|
||||
|
||||
/**
|
||||
* Look in type hierarchy map if a component derived from type exists
|
||||
*/
|
||||
bool GetDerived(EntityId eid, ComponentType ctype, Component*& comp) const;
|
||||
|
||||
// storage for entity objects.
|
||||
typedef std::map<EntityId,Entity*> EntityMap;
|
||||
EntityMap mEntities;
|
||||
|
||||
// controls access to mEntities.
|
||||
mutable OpenThreads::ReadWriteMutex mEntityMutex;
|
||||
|
||||
// Storage for entity systems
|
||||
typedef std::map<ComponentType, EntitySystem*> EntitySystemStore;
|
||||
EntitySystemStore mEntitySystemStore;
|
||||
|
||||
// stores inheritance tree for component types
|
||||
typedef std::multimap<ComponentType, ComponentType> TypeHierarchyMap;
|
||||
TypeHierarchyMap mTypeHierarchy;
|
||||
|
||||
// for publish-subscribe of messages
|
||||
MessagePump mMessagePump;
|
||||
|
||||
ComponentDeletedCallbacks mDeletedCallbacks;
|
||||
|
||||
EntitySystemRequestCallbacks mEntitySystemRequestCallbacks;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool EntityManager::CreateComponent(EntityId eid, T*& component)
|
||||
{
|
||||
assert(eid > 0);
|
||||
Component* c;
|
||||
if(!this->CreateComponent(eid, T::TYPE, c))
|
||||
{
|
||||
component = NULL;
|
||||
return false;
|
||||
}
|
||||
component = static_cast<T*>(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool EntityManager::GetComponent(EntityId eid, T*& component, bool searchDerived)
|
||||
{
|
||||
Component* c;
|
||||
if(this->GetComponent(eid, T::TYPE, c, searchDerived))
|
||||
{
|
||||
assert(dynamic_cast<T*>(c) != NULL);
|
||||
component = static_cast<T*>(c);
|
||||
return true;
|
||||
}
|
||||
component = NULL;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool EntityManager::GetEntitySystem(ComponentType id, T*& es) const
|
||||
{
|
||||
EntitySystem* s = GetEntitySystem(id);
|
||||
es = NULL;
|
||||
if(s == NULL) return false;
|
||||
assert(dynamic_cast<T*>(s) != NULL);
|
||||
es = static_cast<T*>(s);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool EntityManager::GetES(T*& es) const
|
||||
{
|
||||
ComponentType ctype = T::TYPE;
|
||||
EntitySystemStore::const_iterator i = mEntitySystemStore.find(ctype);
|
||||
if(i == mEntitySystemStore.end())
|
||||
{
|
||||
es = NULL;
|
||||
return false;
|
||||
}
|
||||
EntitySystem* s = i->second;
|
||||
assert(dynamic_cast<T*>(s) != NULL);
|
||||
es = static_cast<T*>(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/propertycontainer.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <list>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class Component;
|
||||
class EntityManager;
|
||||
|
||||
|
||||
/**
|
||||
* Each entity system holds a number of components.
|
||||
* Entity systems are themselves responsible for allocating and destroying
|
||||
* their components.
|
||||
*/
|
||||
class EntitySystem
|
||||
: public PropertyContainer
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param id The type id of the component
|
||||
* @param em The entity manager that this system belongs to
|
||||
* @param baseType If component class is derived from component of another entity system then
|
||||
* set the parent component type here. EntityManager::GetComponent will return
|
||||
* components of this entity system when base type is requested.
|
||||
*/
|
||||
EntitySystem(EntityManager& em, ComponentType baseType = StringId())
|
||||
: mBaseType(baseType)
|
||||
, mEntityManager(&em)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~EntitySystem()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The type id of the component that this system handles
|
||||
*/
|
||||
virtual ComponentType GetComponentType() const = 0;
|
||||
/**
|
||||
* @return If component class is derived from a base component type, give base
|
||||
* type here
|
||||
*/
|
||||
ComponentType GetBaseType() const
|
||||
{
|
||||
return mBaseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if a component for this entity exists in the system
|
||||
*/
|
||||
virtual bool HasComponent(EntityId eid) const { return false; }
|
||||
|
||||
/**
|
||||
* @param eid Get component for the entity with this id
|
||||
* @param component Receives the component if found
|
||||
* @return true if found
|
||||
*/
|
||||
virtual bool GetComponent(EntityId eid, Component*& component) { return false; }
|
||||
virtual bool GetComponent(EntityId eid, const Component*& component) { return false; }
|
||||
|
||||
/**
|
||||
* @param eid Create a component for the entity with this id.
|
||||
* @param component Receives the component if it was succesfully created
|
||||
* @return true if success
|
||||
*/
|
||||
virtual bool CreateComponent(EntityId eid, Component*& component) { return false; }
|
||||
|
||||
/**
|
||||
* Delete component. It is best to not call this directly but instead use
|
||||
* the method EntityManager::DeleteComponent. Calling this method
|
||||
* directly will not execute the component deletion callbacks, which
|
||||
* can result in wrappers for that component not being invalidated
|
||||
*
|
||||
* @param eid Delete component for entity with this id
|
||||
* @return true if entity had a component of this type
|
||||
*/
|
||||
virtual bool DeleteComponent(EntityId eid) { return false; }
|
||||
|
||||
/**
|
||||
* Put ids of all entities registered with this system into toFill
|
||||
*/
|
||||
virtual void GetEntitiesInSystem(std::list<EntityId>& toFill) const { }
|
||||
|
||||
/**
|
||||
* Get property names and default property values of component. Used
|
||||
* for spawner creation
|
||||
*/
|
||||
virtual GroupProperty GetComponentProperties() const { return GroupProperty(); }
|
||||
|
||||
/**
|
||||
* @return entity manager that the entity system was added to
|
||||
*/
|
||||
EntityManager& GetEntityManager() const
|
||||
{
|
||||
return *mEntityManager;
|
||||
}
|
||||
|
||||
/** overwrite to react to add to entity manager */
|
||||
virtual void OnAddedToEntityManager(dtEntity::EntityManager& em) {}
|
||||
virtual void OnRemoveFromEntityManager(dtEntity::EntityManager& em) {}
|
||||
|
||||
/**
|
||||
* Override this if components of this entity system should not
|
||||
* be stored to map
|
||||
*/
|
||||
virtual bool StoreComponentToMap(dtEntity::EntityId) const { return true; }
|
||||
|
||||
/**
|
||||
* Override to return false if no spawner should be allowed to spawn this component
|
||||
*/
|
||||
virtual bool AllowComponentCreationBySpawner() const { return true; }
|
||||
|
||||
/**
|
||||
* Override this if properties of this entity system should
|
||||
* be stored to scene file
|
||||
*/
|
||||
virtual bool StorePropertiesToScene() const { return false; }
|
||||
|
||||
private:
|
||||
|
||||
// no copy ctor
|
||||
EntitySystem(EntitySystem&);
|
||||
|
||||
ComponentType mBaseType;
|
||||
EntityManager* mEntityManager;
|
||||
};
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
|
||||
# ifdef DT_ENTITY_LIBRARY
|
||||
# define DT_ENTITY_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define DT_ENTITY_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
# ifdef DT_ENTITY_LIBRARY
|
||||
# define DT_ENTITY_EXPORT __attribute__ ((visibility("default")))
|
||||
# else
|
||||
# define DT_ENTITY_EXPORT
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# pragma warning (disable: 4251)
|
||||
# pragma warning(disable : 4355) // 'this' used in initializer list
|
||||
#endif
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// MurmurHash3 was written by Austin Appleby, and is placed in the public
|
||||
// domain. The author hereby disclaims copyright to this source code.
|
||||
|
||||
#ifndef _MURMURHASH3_H_
|
||||
#define _MURMURHASH3_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Platform-specific functions and macros
|
||||
|
||||
// Microsoft Visual Studio
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if _MSC_VER < 1900
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#endif
|
||||
// Other compilers
|
||||
|
||||
#else // defined(_MSC_VER)
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#endif // !defined(_MSC_VER)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out );
|
||||
|
||||
void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out );
|
||||
|
||||
void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _MURMURHASH3_H_
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/logmanager.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class EntityManager;
|
||||
|
||||
class DT_ENTITY_EXPORT ConsoleLogHandler
|
||||
: public LogListener
|
||||
{
|
||||
public:
|
||||
virtual void LogMessage(dtEntity::LogLevel::e level, const std::string& filename, const std::string& methodname, int linenumber,
|
||||
const std::string& msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* adds required entity systems to entity manager, including map, camera, layer, layerattachpoint.
|
||||
* Registers a number of factories for entity systems that should be started lazily.
|
||||
* Creates application system, passes it the viewer and installs update callback of app system to scene node.
|
||||
* @param argc number of command line args
|
||||
* @param standard c command line args
|
||||
* @param em a valid entity manager
|
||||
*/
|
||||
void DT_ENTITY_EXPORT AddDefaultEntitySystemsAndFactories(int argc, char** argv, dtEntity::EntityManager& em);
|
||||
|
||||
/**
|
||||
* sets osg data paths from command line args or environment variables
|
||||
*/
|
||||
bool DT_ENTITY_EXPORT SetupDataPaths(int argc, char** argv, bool checkPaths);
|
||||
}
|
||||
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
namespace TouchPhase
|
||||
{
|
||||
enum e
|
||||
{
|
||||
UNKNOWN,
|
||||
BEGAN,
|
||||
MOVED,
|
||||
STATIONARY,
|
||||
ENDED
|
||||
};
|
||||
|
||||
std::string ToString(e v);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
struct DT_ENTITY_EXPORT TouchPoint
|
||||
{
|
||||
unsigned int mId;
|
||||
float mX;
|
||||
float mY;
|
||||
unsigned int mTapCount;
|
||||
TouchPhase::e mTouchPhase;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class InputCallbackInterface
|
||||
{
|
||||
public:
|
||||
virtual ~InputCallbackInterface() {}
|
||||
|
||||
virtual bool KeyUp(const std::string& name, bool handled, unsigned int contextid) { return false; }
|
||||
virtual bool KeyDown(const std::string& name, bool handled, unsigned int contextid) { return false; }
|
||||
virtual bool MouseButtonUp(int button, bool handled, unsigned int contextid) { return false; }
|
||||
virtual bool MouseButtonDown(int button, bool handled, unsigned int contextid) { return false; }
|
||||
virtual bool MouseWheel(int dir, bool handled, unsigned int contextid) { return false; }
|
||||
virtual bool MouseMove(float x, float y, bool handled, unsigned int contextid) { return false; }
|
||||
|
||||
virtual void MouseEnterLeave(bool focused, unsigned int contextid) {}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT InputInterface
|
||||
{
|
||||
public:
|
||||
|
||||
static const StringId MouseXId;
|
||||
static const StringId MouseYId;
|
||||
static const StringId MouseXRawId;
|
||||
static const StringId MouseYRawId;
|
||||
static const StringId MouseDeltaXId;
|
||||
static const StringId MouseDeltaYId;
|
||||
static const StringId MouseDeltaXRawId;
|
||||
static const StringId MouseDeltaYRawId;
|
||||
|
||||
virtual ~InputInterface() {}
|
||||
|
||||
/**
|
||||
* Stores if current system is multitouch-capable
|
||||
*/
|
||||
virtual bool GetMultiTouchEnabled() const = 0;
|
||||
virtual void SetMultiTouchEnabled(bool v) = 0;
|
||||
|
||||
/** get or set if mouse cursor should be locked in
|
||||
* center of screen (for FPS style steering)
|
||||
*/
|
||||
virtual bool GetLockCursor() const = 0;
|
||||
virtual void SetLockCursor(bool v) = 0;
|
||||
|
||||
/**
|
||||
* Multitouch interface: return number of touch points
|
||||
*/
|
||||
virtual size_t GetNumTouches() const = 0;
|
||||
|
||||
/**
|
||||
* Multitouch interface: return touch points
|
||||
*/
|
||||
virtual std::vector<TouchPoint> GetTouches() const = 0;
|
||||
|
||||
/**
|
||||
* Return true if key is pressed, else false
|
||||
*/
|
||||
virtual bool GetKey(const std::string& name, unsigned int contextId = 0) const = 0;
|
||||
|
||||
/**
|
||||
* Return true if key was released this frame, else false
|
||||
*/
|
||||
virtual bool GetKeyUp(const std::string& name, unsigned int contextId = 0) const = 0;
|
||||
|
||||
/**
|
||||
* Return true if key was pressed down this frame, else false
|
||||
*/
|
||||
virtual bool GetKeyDown(const std::string& name, unsigned int contextId = 0) const = 0;
|
||||
|
||||
/**
|
||||
* Returns true if any keyboard key is currently pressed
|
||||
*/
|
||||
virtual bool AnyKeyDown() const = 0;
|
||||
|
||||
/**
|
||||
* Return string entered this frame
|
||||
*/
|
||||
virtual std::string GetInputString() const = 0;
|
||||
|
||||
/**
|
||||
* Return true if given mouse button is currently pressed.
|
||||
* 0 for left button, 1 for right, 2 for center
|
||||
*/
|
||||
virtual bool GetMouseButton(int button, unsigned int contextId = 0) const = 0;
|
||||
|
||||
/**
|
||||
* Return true if given mouse button was pressed this frame.
|
||||
* 0 for left button, 1 for right, 2 for center
|
||||
*/
|
||||
virtual bool GetMouseButtonDown(int button, unsigned int contextId = 0) const = 0;
|
||||
|
||||
/**
|
||||
* Return true if given mouse button was released this frame.
|
||||
* 0 for left button, 1 for right, 2 for center
|
||||
*/
|
||||
virtual bool GetMouseButtonUp(int button, unsigned int contextId = 0) const = 0;
|
||||
|
||||
/**
|
||||
* Return axis value from -1 to 1
|
||||
* @TODO: Axes are currently hard coded
|
||||
*/
|
||||
virtual double GetAxis(StringId axisname) const = 0;
|
||||
|
||||
/**
|
||||
* Return current mouse wheel state. -1 = down, 1 = up, 0 = no motion
|
||||
*/
|
||||
virtual int GetMouseWheelState(unsigned int contextId = 0) const = 0;
|
||||
|
||||
virtual void AddInputCallback(InputCallbackInterface*) = 0;
|
||||
virtual bool RemoveInputCallback(InputCallbackInterface*) = 0;
|
||||
|
||||
/**
|
||||
* Return a list containing names of all registered keys
|
||||
*/
|
||||
virtual void GetKeyNames(std::map<std::string, unsigned int>&) const = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/logmanager.h>
|
||||
#include <sstream>
|
||||
|
||||
#define DT_LOG_SOURCE __FILE__, __FUNCTION__, __LINE__
|
||||
|
||||
#define LOG_DEBUG(msg)\
|
||||
{\
|
||||
std::ostringstream os; os << msg; \
|
||||
dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_DEBUG, __FILE__, __FUNCTION__, __LINE__, os.str());\
|
||||
}\
|
||||
|
||||
#define LOG_INFO(msg)\
|
||||
{\
|
||||
std::ostringstream os; os << msg; \
|
||||
dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_INFO, __FILE__, __FUNCTION__, __LINE__, os.str());\
|
||||
}\
|
||||
|
||||
#define LOG_WARNING(msg)\
|
||||
{\
|
||||
std::ostringstream os; os << msg; \
|
||||
dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_WARNING, __FILE__, __FUNCTION__, __LINE__, os.str());\
|
||||
}\
|
||||
|
||||
#define LOG_ERROR(msg)\
|
||||
{\
|
||||
std::ostringstream os; os << msg; \
|
||||
dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_ERROR, __FILE__, __FUNCTION__, __LINE__, os.str());\
|
||||
}\
|
||||
|
||||
#define LOG_ALWAYS(msg)\
|
||||
{\
|
||||
std::ostringstream os; os << msg; \
|
||||
dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_ALWAYS, __FILE__, __FUNCTION__, __LINE__, os.str());\
|
||||
}\
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/singleton.h>
|
||||
#include <osg/Referenced>
|
||||
#include <osg/ref_ptr>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <OpenThreads/Mutex>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
namespace LogLevel
|
||||
{
|
||||
enum e
|
||||
{
|
||||
LVL_ALWAYS,
|
||||
LVL_ERROR,
|
||||
LVL_DEBUG,
|
||||
LVL_WARNING,
|
||||
LVL_INFO
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class LogListener
|
||||
: public osg::Referenced
|
||||
{
|
||||
public:
|
||||
virtual void LogMessage(LogLevel::e level, const std::string& filename, const std::string& methodname, int linenumber,
|
||||
const std::string& msg) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~LogListener() { }
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT LogManager
|
||||
: public dtEntity::Singleton<LogManager>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<osg::ref_ptr<LogListener> > Listeners;
|
||||
|
||||
void LogMessage(LogLevel::e level, const std::string& filename, const std::string& methodname, int linenumber,
|
||||
const std::string& msg) const;
|
||||
|
||||
void AddListener(LogListener* l);
|
||||
void RemoveListener(LogListener* l);
|
||||
|
||||
Listeners::size_type GetNumListeners() const;
|
||||
LogListener* GetListener(Listeners::size_type index) const;
|
||||
|
||||
private:
|
||||
Listeners mListeners;
|
||||
mutable OpenThreads::Mutex mMutex;
|
||||
};
|
||||
|
||||
}
|
||||
+372
@@ -0,0 +1,372 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/componentpluginmanager.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <dtEntity/mapencoder.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/messagefactory.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/spawner.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
struct MapData
|
||||
{
|
||||
std::string mMapPath;
|
||||
std::string mDataPath;
|
||||
unsigned int mSaveOrder;
|
||||
|
||||
MapData(const std::string& mappath, const std::string& datapath, unsigned int order)
|
||||
: mMapPath(mappath)
|
||||
, mDataPath(datapath)
|
||||
, mSaveOrder(order)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* The map component holds information about the entity and how to
|
||||
* serialize it.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT MapComponent : public Component
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const ComponentType TYPE;
|
||||
static const StringId EntityNameId;
|
||||
static const StringId SpawnerNameId;
|
||||
static const StringId MapNameId;
|
||||
static const StringId UniqueIdId;
|
||||
static const StringId SaveWithMapId;
|
||||
static const StringId VisibleInEntityListId;
|
||||
|
||||
MapComponent();
|
||||
virtual ~MapComponent();
|
||||
|
||||
virtual ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual void OnAddedToEntity(Entity& entity) { mOwner = &entity; }
|
||||
|
||||
/**
|
||||
* string identifier of entity. Does not need to be unique. Mainly used
|
||||
* for debugging purposes
|
||||
*/
|
||||
std::string GetEntityName() const;
|
||||
void SetEntityName(const std::string& v);
|
||||
|
||||
/**
|
||||
* If entity was created from a spawner then this is set to the spawners name.
|
||||
* If string is empty then entity was not created by spawner.
|
||||
*/
|
||||
std::string GetSpawnerName() const;
|
||||
void SetSpawnerName(const std::string& v);
|
||||
|
||||
/**
|
||||
* @return the spawner the entity was created from or NULL
|
||||
* if entity was not created from spawner
|
||||
*/
|
||||
Spawner* GetSpawner() const;
|
||||
|
||||
/**
|
||||
* name of map that entity was loaded from and that it will be stored to
|
||||
* if map is saved
|
||||
*/
|
||||
std::string GetMapName() const { return mMapName.Get(); }
|
||||
void SetMapName(const std::string& v) { mMapName.Set(v); }
|
||||
|
||||
/**
|
||||
* A unique identifier identifying the entity. May be a random string.
|
||||
*/
|
||||
std::string GetUniqueId() const { return mUniqueIdStr; }
|
||||
void SetUniqueId(const std::string& v);
|
||||
|
||||
std::string GetDescription() const { return mDescription; }
|
||||
void SetDescription(const std::string& v) { mDescription = v; }
|
||||
|
||||
|
||||
void SetSaveWithMap(bool v) { mSaveWithMap.Set(v); }
|
||||
bool GetSaveWithMap() const { return mSaveWithMap.Get(); }
|
||||
|
||||
void SetVisibleInEntityList(bool v) { mVisibleInEntityList.Set(v); }
|
||||
bool GetVisibleInEntityList() const { return mVisibleInEntityList.Get(); }
|
||||
|
||||
private:
|
||||
DynamicStringProperty mEntityName;
|
||||
StringProperty mMapName;
|
||||
DynamicStringProperty mSpawnerNameProp;
|
||||
DynamicStringProperty mUniqueId;
|
||||
Spawner* mSpawner;
|
||||
std::string mUniqueIdStr;
|
||||
std::string mDescription;
|
||||
std::string mEntityNameStr;
|
||||
BoolProperty mSaveWithMap;
|
||||
BoolProperty mVisibleInEntityList;
|
||||
Entity* mOwner;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DT_ENTITY_EXPORT MapSystem
|
||||
: public DefaultEntitySystem<MapComponent>
|
||||
, public EntityManager::EntitySystemRequestCallback
|
||||
{
|
||||
public:
|
||||
|
||||
friend class MapComponent;
|
||||
static const ComponentType TYPE;
|
||||
typedef DefaultEntitySystem<MapComponent> BaseClass;
|
||||
typedef std::map<std::string, osg::ref_ptr<Spawner> > SpawnerStorage;
|
||||
|
||||
|
||||
MapSystem(EntityManager& em);
|
||||
~MapSystem();
|
||||
|
||||
// overridden to check for uniqueness of unique id
|
||||
virtual bool CreateComponent(EntityId eid, Component*& component);
|
||||
virtual bool DeleteComponent(EntityId eid);
|
||||
|
||||
virtual void OnAddedToEntityManager(dtEntity::EntityManager& em);
|
||||
|
||||
|
||||
/**
|
||||
* Get entity id by unique id. Useful for communicating with the outside world
|
||||
*/
|
||||
EntityId GetEntityIdByUniqueId(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* If entity with this name exists, assign its entity object to &entity and return true.
|
||||
* Else return false.
|
||||
*/
|
||||
bool GetEntityByUniqueId(const std::string& name, Entity*& entity) const;
|
||||
|
||||
// reacts to SpawnEntityMessage
|
||||
void OnSpawnEntity(const Message& msg);
|
||||
|
||||
// reacts to DeleteEntityMessage
|
||||
void OnDeleteEntity(const Message& msg);
|
||||
|
||||
// reacts to StopSystemMessage by removing map system from entity manager
|
||||
void OnStopSystem(const Message& msg);
|
||||
|
||||
/**
|
||||
* Causes a message EntityAddedToSceneMessage to be fired.
|
||||
* Layer system reacts to this by adding assigned node to
|
||||
* scene graph
|
||||
* @param eid Id of entity to add to scene
|
||||
* @return true if success
|
||||
*/
|
||||
bool AddToScene(EntityId eid);
|
||||
|
||||
/**
|
||||
* Causes a EntityRemovedFromSceneMessage to be fired.
|
||||
* Layer system removes attached node from scene graph.
|
||||
* @param eid Id of entity to remove from scene
|
||||
* @return true if success
|
||||
*/
|
||||
bool RemoveFromScene(EntityId eid);
|
||||
|
||||
/**
|
||||
* Register spawner. EntityManager takes ownership of spawner.
|
||||
* @threadsafe
|
||||
*/
|
||||
void AddSpawner(Spawner& spawner);
|
||||
|
||||
/**
|
||||
* Remove spawner registered by this name and delete it.
|
||||
* @return true if spawner was registered under this name
|
||||
* @threadsafe
|
||||
*/
|
||||
bool DeleteSpawner(const std::string& name);
|
||||
|
||||
/**
|
||||
* if spawner is registered under this name, assign it to
|
||||
* @param spawner receives spawner
|
||||
* @return true if success
|
||||
* @threadsafe
|
||||
*/
|
||||
bool GetSpawner(const std::string& name, Spawner*& spawner) const;
|
||||
|
||||
/**
|
||||
* fill up a map with all spawners indexed by their name
|
||||
* @threadsafe
|
||||
*/
|
||||
void GetAllSpawners(std::map<std::string, Spawner*>& toFill) const;
|
||||
|
||||
/**
|
||||
* fill up a list with names of all registered spawners
|
||||
* @threadsafe
|
||||
*/
|
||||
void GetAllSpawnerNames(std::vector<std::string>& toFill) const;
|
||||
|
||||
/**
|
||||
* Call spawner to let it set up entity
|
||||
* @param name Name of spawner
|
||||
* @param spawned A valid, created entity
|
||||
* @return true if success
|
||||
* @threadsafe
|
||||
*/
|
||||
bool Spawn(const std::string& name, Entity& spawned) const;
|
||||
|
||||
void GetSpawnerCreatedEntities(const std::string& spawnername, std::vector<EntityId>& ids, bool recursive = true) const;
|
||||
|
||||
/**
|
||||
* @return true if entity exists and was spawned by spawner or one of its child spawners
|
||||
*/
|
||||
bool IsSpawnOf(EntityId, const std::string& spawnername) const;
|
||||
|
||||
/**
|
||||
* Load scene from map file, start and configure entity systems
|
||||
* as appropriate, load maps
|
||||
*/
|
||||
bool LoadScene(const std::string& path);
|
||||
|
||||
/**
|
||||
* Unload all maps
|
||||
*/
|
||||
bool UnloadScene();
|
||||
|
||||
|
||||
/**
|
||||
* Save entity system configurations to scene file,
|
||||
* @param path Save scene file to this path
|
||||
* @param saveAllMaps if set, save all currently loaded maps to map files
|
||||
*/
|
||||
bool SaveScene(const std::string& path, bool saveAllMaps = true);
|
||||
|
||||
/**
|
||||
* Return true if map is found in file system
|
||||
*/
|
||||
bool MapExists(const std::string& path);
|
||||
|
||||
/**
|
||||
* Load a single map
|
||||
*/
|
||||
bool LoadMap(const std::string& path);
|
||||
|
||||
/**
|
||||
* Unload a single map
|
||||
*/
|
||||
bool UnloadMap(const std::string& path);
|
||||
|
||||
/**
|
||||
*Get an index representing the order in which maps should be loaded / saved
|
||||
* Maps with lowest values are loaded first
|
||||
*/
|
||||
unsigned int GetMapSaveOrder(const std::string& path);
|
||||
void SetMapSaveOrder(const std::string& path, int);
|
||||
|
||||
/**
|
||||
* Delete instances that were created from given map
|
||||
*/
|
||||
bool DeleteEntitiesByMap(const std::string& mapName);
|
||||
|
||||
/**
|
||||
* Save a single map
|
||||
*/
|
||||
bool SaveMap(const std::string& path);
|
||||
|
||||
/**
|
||||
* Save a single map as a copy
|
||||
*/
|
||||
bool SaveMapAs(const std::string& path, const std::string& copyname);
|
||||
|
||||
/**
|
||||
* Add an empty, named map to system
|
||||
*/
|
||||
bool AddEmptyMap(const std::string& dataPath, const std::string& mapname);
|
||||
|
||||
/**
|
||||
* Check if a map of that name exists
|
||||
*/
|
||||
bool IsMapLoaded(const std::string& mapName) const;
|
||||
|
||||
/**
|
||||
* Get a list of all maps in system
|
||||
*/
|
||||
std::vector<std::string> GetLoadedMaps() const;
|
||||
|
||||
/**
|
||||
* Get all entities that are stored to this map
|
||||
*/
|
||||
void GetEntitiesInMap(const std::string& mapname, std::vector<EntityId>& toFill) const;
|
||||
|
||||
// implementation of EntityManager::EntitySystemRequestCallback interface
|
||||
virtual bool CreateEntitySystem(EntityManager* em, ComponentType t);
|
||||
|
||||
void AddMapEncoder(MapEncoder* ec);
|
||||
|
||||
MapEncoder* GetEncoderForMap(const std::string& extension) const;
|
||||
MapEncoder* GetEncoderForScene(const std::string& extension) const;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* called by component. Don't call, please set the property on
|
||||
* the component instead
|
||||
* returns true if change succeeded, false if an entity with this id already exists
|
||||
*/
|
||||
bool OnEntityChangedUniqueId(EntityId id, const std::string& oldUniqueId, const std::string& newUniqueid);
|
||||
|
||||
|
||||
/**
|
||||
* Handles SetComponentPropertiesMessage
|
||||
*/
|
||||
void OnSetComponentProperties(const Message& m);
|
||||
|
||||
/**
|
||||
* Handles SetSystemPropertiesMessage
|
||||
*/
|
||||
void OnSetSystemProperties(const Message& m);
|
||||
|
||||
void EmitSpawnerDeleteMessages(MapSystem::SpawnerStorage& spawners, const std::string& path);
|
||||
|
||||
typedef std::vector<MapData> LoadedMaps;
|
||||
LoadedMaps mLoadedMaps;
|
||||
|
||||
// store spawners in a map
|
||||
SpawnerStorage mSpawners;
|
||||
|
||||
// functors for registering to messages
|
||||
MessageFunctor mSpawnEntityFunctor;
|
||||
MessageFunctor mDeleteEntityFunctor;
|
||||
MessageFunctor mResetSystemFunctor;
|
||||
MessageFunctor mStopSystemFunctor;
|
||||
MessageFunctor mSetComponentPropertiesFunctor;
|
||||
MessageFunctor mSetSystemPropertiesFunctor;
|
||||
ComponentPluginManager mPluginManager;
|
||||
|
||||
std::map<std::string, EntityId> mEntitiesByUniqueId;
|
||||
|
||||
typedef std::vector<MapEncoder*> MapEncoders;
|
||||
MapEncoders mMapEncoders;
|
||||
};
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
/**
|
||||
* Pure virtual interface for loading and saving scene data to maps
|
||||
*/
|
||||
class MapEncoder
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual ~MapEncoder() {}
|
||||
|
||||
virtual bool LoadMapFromFile(const std::string& path) = 0;
|
||||
|
||||
// empty destination means overwrite mapPath
|
||||
virtual bool SaveMapToFile(const std::string& mapPath, const std::string& destination) = 0;
|
||||
|
||||
virtual bool LoadSceneFromFile(const std::string& path) = 0;
|
||||
virtual bool SaveSceneToFile(const std::string& path) = 0;
|
||||
|
||||
virtual bool AcceptsMapExtension(const std::string& /*extension*/) const = 0;
|
||||
virtual bool AcceptsSceneExtension(const std::string& /*extension*/) const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/propertycontainer.h>
|
||||
#include <assert.h>
|
||||
#include <dtEntity/FastDelegate.h>
|
||||
#include <dtEntity/FastDelegateBind.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* Pure virtual Message interface class. Holds a number of properties
|
||||
*/
|
||||
class DT_ENTITY_EXPORT Message
|
||||
: public PropertyContainer
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*/
|
||||
Message()
|
||||
: mType(MessageType())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param type The unique class ID of the message class
|
||||
*/
|
||||
Message(MessageType type)
|
||||
: mType(type)
|
||||
{
|
||||
assert(mType != dtEntity::StringId() && "No message type set!");
|
||||
}
|
||||
|
||||
// DTor
|
||||
virtual ~Message()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class type id of message
|
||||
*/
|
||||
MessageType GetType() const { return mType; }
|
||||
|
||||
/**
|
||||
* Create a copy of the message on the heap.
|
||||
* Example generic implementation:
|
||||
* virtual Message* Clone() const { return CloneContainer<MyMessageClass>(); }
|
||||
*/
|
||||
virtual Message* Clone() const {
|
||||
assert(mType != StringId() && "Cannot clone a message without type!");
|
||||
return CloneContainer<Message>();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// no copy CTor
|
||||
Message(const Message& other);
|
||||
|
||||
MessageType mType;
|
||||
};
|
||||
|
||||
// Functors of this type can be registered to receive messages of a specific type.
|
||||
typedef fastdelegate::FastDelegate1< const Message&, void> MessageFunctor;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/objectfactory.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/singleton.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
class DT_ENTITY_EXPORT MessageFactory
|
||||
: public Singleton<MessageFactory>
|
||||
{
|
||||
public:
|
||||
|
||||
MessageFactory() {}
|
||||
|
||||
/**
|
||||
* Register a message type with the message factory
|
||||
* The template parameter holds the message class to instantiate
|
||||
* Usage example:
|
||||
* mMessageFactory->RegisterMessageType<TickMessage>(TickMessage::TYPE);
|
||||
* @param mtype MessageType id of message
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
void RegisterMessageType(MessageType mtype)
|
||||
{
|
||||
mMessageFactory.template RegisterType<T>(mtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* fill up a vector with the types of all registered messages
|
||||
*/
|
||||
void GetRegisteredMessageTypes(std::vector<MessageType>& toFill);
|
||||
|
||||
/**
|
||||
* Create a message of given type. A message class has to be registered with
|
||||
* RegisterMessageType before it can be instantiated with CreateMessage.
|
||||
* Please note that you can simply create messages with 'new', this is
|
||||
* just a factory for generic script- and tool-side access
|
||||
* @param msgType type id of message class
|
||||
* @param msg Receives newly created message. Ownership of the message object
|
||||
* is transfered to caller - post your message or delete it!
|
||||
* @return true if success - false if message type is not registered
|
||||
*/
|
||||
bool CreateMessage(MessageType msgType, Message*& msg) const;
|
||||
|
||||
// not implemented
|
||||
MessageFactory(const MessageFactory& other);
|
||||
|
||||
private:
|
||||
// factory for message objects
|
||||
ObjectFactory<MessageType, Message> mMessageFactory;
|
||||
|
||||
};
|
||||
}
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/threadsafequeue.h>
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
namespace FilterOptions
|
||||
{
|
||||
/* These bits define the way a functor is registered to a message.
|
||||
* When multiple functors are registered to a message type then they are called
|
||||
* in the order of their PRIORITY (highest priority first).
|
||||
* The UNREGISTERED bit has to be set to false. It is used internally to mark
|
||||
* deregistered functors for removal.
|
||||
*
|
||||
* If SINGLE_SHOT is set then the functor is unregistered after it is called the first time.
|
||||
* Registrants can register for local messages, network messages, or both.
|
||||
* Message senders can send a message to local or network or both.
|
||||
*/
|
||||
enum e
|
||||
{
|
||||
PRIORITY_LOWEST = 0,
|
||||
PRIORITY_DEFAULT = 1,
|
||||
PRIORITY_HIGHER = 2,
|
||||
PRIORITY_HIGHEST = 3,
|
||||
ORDER_LATE = 0,
|
||||
ORDER_DEFAULT = 1,
|
||||
ORDER_EARLY = 2,
|
||||
ORDER_EARLIEST = 3,
|
||||
UNREGISTERED = (1<<3),
|
||||
SINGLE_SHOT = (1<<4),
|
||||
|
||||
DEFAULT = ORDER_DEFAULT
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/*
|
||||
* Internal data structure for message registration
|
||||
*/
|
||||
struct MsgRegistryEntry
|
||||
{
|
||||
unsigned int mOptions;
|
||||
MessageFunctor mFunctor;
|
||||
StringId mFuncName;
|
||||
};
|
||||
|
||||
struct FutureMessageEntry
|
||||
{
|
||||
double mTimeToPost;
|
||||
Message* mMessage;
|
||||
};
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// pure virtual interface
|
||||
class MessageReceiver
|
||||
{
|
||||
public:
|
||||
~MessageReceiver() {}
|
||||
virtual void Receive(const dtEntity::Message& msg) = 0;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class DT_ENTITY_EXPORT MessagePump
|
||||
: public MessageReceiver
|
||||
{
|
||||
public:
|
||||
|
||||
// thread safe message queue. The int stores the sending options.
|
||||
typedef ThreadSafeQueue<const Message*> MessageQueue;
|
||||
typedef ThreadSafeQueue<FutureMessageEntry> FutureMessageQueue;
|
||||
|
||||
/**
|
||||
* CTor
|
||||
*/
|
||||
MessagePump();
|
||||
|
||||
/**
|
||||
* DTor
|
||||
*/
|
||||
virtual ~MessagePump();
|
||||
|
||||
/**
|
||||
* Register a functor to be called when a message of given type is emitted.
|
||||
* @param msgtype Type of message to register to
|
||||
* @param ftr This functor is called when a message of msgtype is emitted
|
||||
* @param options Option bits for registration (see FilterOptions comments)
|
||||
* @param funcname name for debugging and profiling purposes
|
||||
*
|
||||
*/
|
||||
virtual void RegisterForMessages(MessageType msgtype, const MessageFunctor &ftr, unsigned int options = FilterOptions::DEFAULT, const std::string& funcname = "");
|
||||
|
||||
/**
|
||||
* Unregister functor from message
|
||||
* @param msgtype Type of message to unregister from
|
||||
* @param ftr Unregister this message
|
||||
* @return true if success
|
||||
*/
|
||||
virtual bool UnregisterForMessages(MessageType msgtype, const MessageFunctor& ftr);
|
||||
|
||||
/**
|
||||
* returns true if functor is registered to message
|
||||
*/
|
||||
virtual bool IsRegistered(MessageType msgtype, const MessageFunctor& ftr);
|
||||
|
||||
/**
|
||||
* Immediately send a message to all registered functors
|
||||
* Warning: beware of circular dependencies!
|
||||
* @param msg The message to send
|
||||
*/
|
||||
void EmitMessage(const Message& msg);
|
||||
|
||||
/**
|
||||
* Enqueue message and emit it on next PreFrame event
|
||||
* @param when Future simulation time that event should be emitted at
|
||||
* ( 0 means emit immediately)
|
||||
*/
|
||||
void EnqueueMessage(const Message& msg);
|
||||
void EnqueueMessage(const Message& msg, double when);
|
||||
|
||||
// implement MessageReceiver interface
|
||||
virtual void Receive(const dtEntity::Message& msg)
|
||||
{
|
||||
EnqueueMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit all messages in message queue
|
||||
*/
|
||||
void EmitQueuedMessages(double simtime);
|
||||
|
||||
/**
|
||||
* Discard all queued messages
|
||||
*/
|
||||
void ClearQueue();
|
||||
|
||||
/**
|
||||
* Unregister all functors
|
||||
*/
|
||||
void UnregisterAll();
|
||||
|
||||
protected:
|
||||
|
||||
// Registry for message functors
|
||||
typedef std::multimap<MessageType, MsgRegistryEntry> MessageFunctorRegistry;
|
||||
MessageFunctorRegistry mMessageFunctors;
|
||||
|
||||
|
||||
// stores messages til next tick
|
||||
MessageQueue mMessageQueue;
|
||||
|
||||
FutureMessageQueue mFutureMessageQueue;
|
||||
// stores messages until their time to post has come
|
||||
std::list<FutureMessageEntry> mFutureMessages;
|
||||
|
||||
};
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
namespace NodeMasks
|
||||
{
|
||||
enum e
|
||||
{
|
||||
REFLECTION_SCENE = (1 << 0), // OSGOcean
|
||||
REFRACTION_SCENE = (1 << 1), // OSGOcean
|
||||
NORMAL_SCENE = (1 << 2), // OSGOcean
|
||||
SURFACE_MASK = (1 << 3), // OSGOcean
|
||||
SILT_MASK = (1 << 4), // OSGOcean
|
||||
VISIBLE = (1 << 5),
|
||||
PICKABLE = (1 << 6),
|
||||
TERRAIN = (1 << 7),
|
||||
CASTS_SHADOWS = (1 << 8),
|
||||
RECEIVES_SHADOWS = (1 << 9),
|
||||
MANIPULATOR = (1 << 10)
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Matthew W. Campbell
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
/**
|
||||
* Templated function to provide a generic object construction
|
||||
* utility.
|
||||
*/
|
||||
template<typename BaseType, typename DerivedType>
|
||||
BaseType *construct()
|
||||
{
|
||||
return new DerivedType();
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is a template object factory. It allows one to
|
||||
* create any type of object as long as there is a common base
|
||||
* class. The common base class is defined on a per-factory
|
||||
* basis using the templated parameter <code>BaseType</code>.
|
||||
* @note
|
||||
* The ObjectFactory implementation only supports objects with
|
||||
* a default constructor. It will not work with objects that
|
||||
* only have named constructors.
|
||||
*/
|
||||
template<typename UniqueIdTypeClass,typename BaseTypeClass,typename ltCmpClass=std::less<UniqueIdTypeClass> >
|
||||
class ObjectFactory
|
||||
{
|
||||
public:
|
||||
|
||||
typedef UniqueIdTypeClass UniqueIdType;
|
||||
typedef BaseTypeClass BaseType;
|
||||
typedef ltCmpClass ltCmp;
|
||||
|
||||
typedef BaseType *(*createObjectFunc)(); /// Function pointer type for functions creating objects.
|
||||
typedef std::map<UniqueIdType,createObjectFunc,ltCmp> ObjectMap;
|
||||
typedef typename ObjectMap::iterator ObjTypeItor;
|
||||
typedef typename ObjectMap::const_iterator ObjTypeItorConst;
|
||||
ObjectFactory() {} // constructor
|
||||
|
||||
|
||||
/**
|
||||
* Registers a new type of object with the factory.
|
||||
* @return false if the type is a duplicate.
|
||||
*/
|
||||
template<typename DerivedType>
|
||||
bool RegisterType(UniqueIdType id)
|
||||
{
|
||||
if (this->objectTypeMap.find(id) != this->objectTypeMap.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this->objectTypeMap[id] = &construct<BaseType,DerivedType>;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an existing object type from the factory's known list
|
||||
* of object types.
|
||||
*/
|
||||
void RemoveType(UniqueIdType id) {
|
||||
this->objectTypeMap.erase(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the factory can create objects of the given type.
|
||||
* @param id The type of object to check for.
|
||||
* @return True if the type is supported, false otherwise.
|
||||
*/
|
||||
bool IsTypeSupported(UniqueIdType id) const
|
||||
{
|
||||
ObjTypeItorConst itor(this->objectTypeMap.find(id));
|
||||
if (itor != this->objectTypeMap.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of types that this factory knows how to create.
|
||||
*/
|
||||
void GetSupportedTypes(std::vector<UniqueIdType> &types) const
|
||||
{
|
||||
types.clear();
|
||||
for (ObjTypeItorConst itor=this->objectTypeMap.begin();
|
||||
itor != this->objectTypeMap.end(); ++itor)
|
||||
{
|
||||
types.push_back(itor->first);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new object.
|
||||
* @param id - Type of object to create.
|
||||
* @return Returns a pointer to the newly created object or NULL if the given id has not been registered.
|
||||
* @throw Exception is thrown if the factory does not know how to create
|
||||
* the requested type.
|
||||
*/
|
||||
BaseType* CreateObject(const UniqueIdType id) const
|
||||
{
|
||||
ObjTypeItorConst itor(this->objectTypeMap.find(id));
|
||||
|
||||
// We cannot create a new object if we do not know what type it is
|
||||
// so throw an exception.
|
||||
if (itor == this->objectTypeMap.end())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (itor->second)();
|
||||
}
|
||||
|
||||
const ObjectMap& GetMap() const { return objectTypeMap; }
|
||||
|
||||
private:
|
||||
///Maps a unique id to a function pointer that when called creates an
|
||||
///object of the appropriate type.
|
||||
ObjectMap objectTypeMap;
|
||||
};
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
#pragma once
|
||||
|
||||
/***************************************************************************************************
|
||||
**
|
||||
** profile.h
|
||||
**
|
||||
** Real-Time Hierarchical Profiling for Game Programming Gems 3
|
||||
**
|
||||
** by Greg Hjelstrom & Byon Garrabrant
|
||||
**
|
||||
***************************************************************************************************/
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <dtEntity/systeminterface.h>
|
||||
/*
|
||||
** A node in the Profile Hierarchy Tree
|
||||
*/
|
||||
class CProfileNode {
|
||||
|
||||
public:
|
||||
CProfileNode( dtEntity::StringId name, CProfileNode * parent );
|
||||
~CProfileNode( void );
|
||||
|
||||
CProfileNode * Get_Sub_Node( dtEntity::StringId name );
|
||||
|
||||
CProfileNode * Get_Parent( void ) { return Parent; }
|
||||
CProfileNode * Get_Sibling( void ) { return Sibling; }
|
||||
CProfileNode * Get_Child( void ) { return Child; }
|
||||
|
||||
void Reset( void );
|
||||
void Call( void );
|
||||
bool Return( void );
|
||||
|
||||
const dtEntity::StringId Get_Name( void ) { return Name; }
|
||||
int Get_Total_Calls( void ) { return TotalCalls; }
|
||||
float Get_Total_Time( void ) { return TotalTime; }
|
||||
|
||||
protected:
|
||||
|
||||
dtEntity::StringId Name;
|
||||
int TotalCalls;
|
||||
float TotalTime;
|
||||
dtEntity::Timer_t StartTime;
|
||||
int RecursionCounter;
|
||||
|
||||
CProfileNode * Parent;
|
||||
CProfileNode * Child;
|
||||
CProfileNode * Sibling;
|
||||
};
|
||||
|
||||
/*
|
||||
** An iterator to navigate through the tree
|
||||
*/
|
||||
class CProfileIterator
|
||||
{
|
||||
public:
|
||||
// Access all the children of the current parent
|
||||
void First(void);
|
||||
void Next(void);
|
||||
bool Is_Done(void);
|
||||
bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
|
||||
|
||||
void Enter_Child( int index ); // Make the given child the new parent
|
||||
void Enter_Largest_Child( void ); // Make the largest child the new parent
|
||||
void Enter_Parent( void ); // Make the current parent's parent the new parent
|
||||
|
||||
// Access the current child
|
||||
dtEntity::StringId Get_Current_Name( void ) { return CurrentChild->Get_Name(); }
|
||||
int Get_Current_Total_Calls( void ) { return CurrentChild->Get_Total_Calls(); }
|
||||
float Get_Current_Total_Time( void ) { return CurrentChild->Get_Total_Time(); }
|
||||
|
||||
// Access the current parent
|
||||
const dtEntity::StringId Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); }
|
||||
int Get_Current_Parent_Total_Calls( void ) { return CurrentParent->Get_Total_Calls(); }
|
||||
float Get_Current_Parent_Total_Time( void ) { return CurrentParent->Get_Total_Time(); }
|
||||
|
||||
protected:
|
||||
|
||||
CProfileNode * CurrentParent;
|
||||
CProfileNode * CurrentChild;
|
||||
|
||||
CProfileIterator( CProfileNode * start );
|
||||
friend class CProfileManager;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** The Manager for the Profile system
|
||||
*/
|
||||
class DT_ENTITY_EXPORT CProfileManager {
|
||||
public:
|
||||
static void Start_Profile( dtEntity::StringId name );
|
||||
static void Stop_Profile( void );
|
||||
|
||||
static void Reset( void );
|
||||
static void Increment_Frame_Counter( void );
|
||||
static int Get_Frame_Count_Since_Reset( void ) { return FrameCounter; }
|
||||
static float Get_Time_Since_Reset( void );
|
||||
|
||||
static CProfileIterator * Get_Iterator( void ) { return new CProfileIterator( &Root ); }
|
||||
static void Release_Iterator( CProfileIterator * iterator ) { delete iterator; }
|
||||
|
||||
static void dumpRecursive(CProfileIterator* profileIterator, int spacing);
|
||||
static void dumpAll();
|
||||
private:
|
||||
static CProfileNode Root;
|
||||
static CProfileNode* CurrentNode;
|
||||
static int FrameCounter;
|
||||
static dtEntity::Timer_t ResetTime;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** ProfileSampleClass is a simple way to profile a function's scope
|
||||
** Use the PROFILE macro at the start of scope to time
|
||||
*/
|
||||
class CProfileSample {
|
||||
public:
|
||||
CProfileSample( dtEntity::StringId name )
|
||||
{
|
||||
CProfileManager::Start_Profile( name );
|
||||
}
|
||||
|
||||
~CProfileSample( void )
|
||||
{
|
||||
CProfileManager::Stop_Profile();
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define PROFILE( name ) CProfileSample __profile( name )
|
||||
#else
|
||||
#define PROFILE( name )
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
+1017
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,147 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <dtEntity/dtentity_config.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class Property;
|
||||
|
||||
/**
|
||||
* Holds a number of properties. This container does NOT take ownership
|
||||
* of properties, they are not deleted in the constructor.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT PropertyContainer : public GroupProperty
|
||||
{
|
||||
public:
|
||||
|
||||
PropertyContainer() {}
|
||||
|
||||
virtual ~PropertyContainer()
|
||||
{
|
||||
// don't delete properties, they are not on heap
|
||||
mValue.clear();
|
||||
}
|
||||
|
||||
#if CALL_ONPROPERTYCHANGED_METHOD == 0
|
||||
// hide when compiling with new property system
|
||||
private:
|
||||
#endif
|
||||
/**
|
||||
* Can be overridden to react to changes of properties.
|
||||
* Should be called by user when changing a property on the
|
||||
* PropertyContainer.
|
||||
*/
|
||||
virtual void OnPropertyChanged(StringId propname, Property& prop) {}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* should be called when a set of interdependent
|
||||
* properties were changed.
|
||||
* The component can overwrite this method to react to these
|
||||
* changes.
|
||||
*/
|
||||
virtual void Finished() {}
|
||||
|
||||
/**
|
||||
* template helper for creating Clone() methods
|
||||
*/
|
||||
template <class T>
|
||||
T* CloneContainer() const;
|
||||
|
||||
/**
|
||||
* Copy property values from other to this
|
||||
*/
|
||||
void InitFrom(const PropertyContainer& other);
|
||||
|
||||
/**
|
||||
* Set value of property registered with given string id.
|
||||
* In debug mode this throws an assertion when a component
|
||||
* is set to a wrong type.
|
||||
*/
|
||||
void SetArray(StringId name, const std::vector<Property*>& val);
|
||||
void SetBool(StringId name, bool val);
|
||||
void SetDouble(StringId name, double val);
|
||||
void SetFloat(StringId name, float val);
|
||||
void SetGroup(StringId name, const std::map<StringId, Property*>& val);
|
||||
void SetInt(StringId name, int val);
|
||||
void SetMatrix(StringId name, const Matrix& val);
|
||||
void SetQuat(StringId name, const Quat& val);
|
||||
void SetString(StringId name, const std::string& val);
|
||||
void SetStringId(StringId name, StringId val);
|
||||
void SetUInt(StringId name, unsigned int val);
|
||||
void SetVec2(StringId name, const Vec2f& val);
|
||||
void SetVec3(StringId name, const Vec3f& val);
|
||||
void SetVec4(StringId name, const Vec4f& val);
|
||||
void SetVec2d(StringId name, const Vec2d& val);
|
||||
void SetVec3d(StringId name, const Vec3d& val);
|
||||
void SetVec4d(StringId name, const Vec4d& val);
|
||||
|
||||
/**
|
||||
* Return value of property registered with given string id
|
||||
*/
|
||||
std::vector<Property*> GetArray(StringId name) const;
|
||||
bool GetBool(StringId name) const;
|
||||
double GetDouble(StringId name) const;
|
||||
float GetFloat(StringId name) const;
|
||||
std::map<StringId, Property*> GetGroup(StringId name) const;
|
||||
int GetInt(StringId name) const;
|
||||
Matrix GetMatrix(StringId name) const;
|
||||
Quat GetQuat(StringId name) const;
|
||||
std::string GetString(StringId name) const;
|
||||
StringId GetStringId(StringId name) const;
|
||||
unsigned int GetUInt(StringId name) const;
|
||||
Vec2f GetVec2(StringId name) const;
|
||||
Vec3f GetVec3(StringId name) const;
|
||||
Vec4f GetVec4(StringId name) const;
|
||||
Vec2d GetVec2d(StringId name) const;
|
||||
Vec3d GetVec3d(StringId name) const;
|
||||
Vec4d GetVec4d(StringId name) const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Register a property under the given string id
|
||||
*/
|
||||
void Register(StringId name, Property* prop);
|
||||
|
||||
private:
|
||||
|
||||
// no copy constructor
|
||||
PropertyContainer(const PropertyContainer& other);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
T* PropertyContainer::CloneContainer() const
|
||||
{
|
||||
T* ret = new T();
|
||||
ret->InitFrom(*this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/entitymanager.h>
|
||||
#include <dtEntity/mapencoder.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <rapidxml.hpp>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
class Spawner;
|
||||
class MapSystem;
|
||||
class Property;
|
||||
|
||||
class DT_ENTITY_EXPORT RapidXMLMapEncoder
|
||||
: public MapEncoder
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RapidXMLMapEncoder(EntityManager& em);
|
||||
virtual ~RapidXMLMapEncoder();
|
||||
|
||||
virtual bool LoadMapFromFile(const std::string& path);
|
||||
|
||||
// empty destination means overwrite mapPath
|
||||
virtual bool SaveMapToFile(const std::string& mapPath, const std::string& destination = "");
|
||||
|
||||
virtual bool LoadSceneFromFile(const std::string& path);
|
||||
|
||||
// empty dest means overwrite original file
|
||||
virtual bool SaveSceneToFile(const std::string& path);
|
||||
|
||||
virtual bool AcceptsMapExtension(const std::string& extension) const
|
||||
{
|
||||
return extension == "dtemap";
|
||||
}
|
||||
|
||||
virtual bool AcceptsSceneExtension(const std::string& extension) const
|
||||
{
|
||||
return extension == "dtescene";
|
||||
}
|
||||
|
||||
static dtEntity::Property* ParseProperty(rapidxml::xml_node<>* element);
|
||||
|
||||
// create XML nodes for properties and add them to parent node
|
||||
static void SerializeProperties(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* parent, const std::map<std::string, const Property*>& props);
|
||||
|
||||
private:
|
||||
|
||||
EntityManager* mEntityManager;
|
||||
MapSystem* mMapSystem;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/singleton.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class EntityManager;
|
||||
|
||||
namespace ResourceManagerOptions
|
||||
{
|
||||
enum e
|
||||
{
|
||||
DeepCopy = 1<<0, // If in cache: Create copy of node and all of its subnodes
|
||||
ShallowCopy = 1<<1, // If in cache: Create copy of node, share subnodes of cached node
|
||||
CopyNodes = 1<<2, // If in cache: Create copy of node and subnodes, share vertices, textures etc
|
||||
CopyHardwareMeshes = 1<<3, // If in cache: Special mode for efficiently sharing osgAnimation objects
|
||||
DoOptimization = 1<<4, // Run osgUtil::Optimizer on first load
|
||||
Default = ShallowCopy
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class DT_ENTITY_EXPORT ResourceManager
|
||||
: public dtEntity::Singleton<ResourceManager>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<std::string, osg::ref_ptr<osg::Node> > NodeStore;
|
||||
|
||||
/**
|
||||
* Try to read node from data paths.
|
||||
* @param path Load resource from this path
|
||||
* @param options Loading options.
|
||||
* @return node, NULL if not found
|
||||
*/
|
||||
osg::ref_ptr<osg::Node> GetNode(EntityManager& em, const std::string& path, unsigned int options = ResourceManagerOptions::Default);
|
||||
|
||||
/**
|
||||
* @return true if this resource resides in the cache
|
||||
*/
|
||||
bool IsInNodeCache(const std::string& path);
|
||||
|
||||
/**
|
||||
* remove from cache
|
||||
* @return true if this resource was in the cache
|
||||
*/
|
||||
bool RemoveFromNodeCache(const std::string& path);
|
||||
|
||||
/**
|
||||
* Call this method to notify the resource manager that this resource has changed
|
||||
* and should be reloaded
|
||||
*/
|
||||
void TriggerReload(const std::string& path, EntityManager& em);
|
||||
|
||||
private:
|
||||
NodeStore mNodeStore;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/FastDelegate.h>
|
||||
#include <dtEntity/FastDelegateBind.h>
|
||||
#include <vector>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
|
||||
typedef std::vector<const Property*> PropertyArgs;
|
||||
typedef fastdelegate::FastDelegate1<const PropertyArgs&, Property*> ScriptMethodFunctor;
|
||||
|
||||
class DT_ENTITY_EXPORT ScriptAccessor
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~ScriptAccessor() { }
|
||||
|
||||
void AddScriptedMethod(const std::string& methodname, const ScriptMethodFunctor& functor);
|
||||
|
||||
// Caller is responsible for deleting the returned property!
|
||||
Property* CallScriptedMethod(const std::string& methodname, const PropertyArgs& args) const;
|
||||
|
||||
void GetMethodNames(std::vector<std::string>& names) const;
|
||||
|
||||
private:
|
||||
std::map<std::string,ScriptMethodFunctor> mFunctors;
|
||||
};
|
||||
}
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
/** simple singleton class. Not thread safe!
|
||||
*/
|
||||
template <typename T>
|
||||
class Singleton
|
||||
{
|
||||
public:
|
||||
|
||||
static T& GetInstance()
|
||||
{
|
||||
if (mInstance == 0)
|
||||
{
|
||||
mInstance = new T;
|
||||
}
|
||||
|
||||
return *mInstance;
|
||||
};
|
||||
|
||||
static void DestroyInstance()
|
||||
{
|
||||
if(mInstance != 0)
|
||||
{
|
||||
delete mInstance;
|
||||
mInstance = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Singleton()
|
||||
{
|
||||
};
|
||||
|
||||
virtual ~Singleton()
|
||||
{
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
Singleton(const Singleton& source)
|
||||
{
|
||||
};
|
||||
|
||||
static T* mInstance;
|
||||
};
|
||||
|
||||
template <typename T> T* Singleton<T>::mInstance = 0;
|
||||
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osg/Referenced>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class Entity;
|
||||
|
||||
/**
|
||||
* Spawner: a template for creating entities.
|
||||
* Each spawner contains a number of components which contain properties.
|
||||
* When Spawner::Spawn is called, components are created for the passed entity and
|
||||
* their properties are set to specified values.
|
||||
* Spawners can form a sort of inheritance tree. When a child spawner is used to
|
||||
* spawn an entity, all components defined in the spawner and its parent chain are
|
||||
* created. Children spawners can overwrite the property values of their parents.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT Spawner : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<ComponentType, GroupProperty> ComponentProperties;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Spawner(const std::string& name, const std::string& mapName, Spawner* parent = NULL);
|
||||
|
||||
/**
|
||||
*return name of spawner
|
||||
*/
|
||||
std::string GetName() const { return mName; }
|
||||
|
||||
/**
|
||||
*return name of map this spawner was loaded from
|
||||
*/
|
||||
std::string GetMapName() const { return mMapName; }
|
||||
void SetMapName(const std::string& v) { mMapName = v; }
|
||||
|
||||
/**
|
||||
* Should spawner show up in spawner drag & drop GUI?
|
||||
*/
|
||||
bool GetAddToSpawnerStore() const { return mAddToSpawnerStore; }
|
||||
void SetAddToSpawnerStore(bool v) { mAddToSpawnerStore = v; }
|
||||
|
||||
/**
|
||||
* category for spawner store
|
||||
*/
|
||||
std::string GetGUICategory() { return mGUICategory; }
|
||||
void SetGUICategory(const std::string& v) { mGUICategory = v; }
|
||||
|
||||
/**
|
||||
* icon for representing spawner in GUI
|
||||
*/
|
||||
std::string GetIconPath() { return mIconPath; }
|
||||
void SetIconPath(const std::string& v) { mIconPath = v; }
|
||||
|
||||
/**
|
||||
*return name of map this spawner was loaded from
|
||||
*/
|
||||
Spawner* GetParent() { return mParent; }
|
||||
const Spawner* GetParent() const { return mParent; }
|
||||
|
||||
/**
|
||||
* Collect all components of entity and all properties of these components
|
||||
* and store them
|
||||
*/
|
||||
void InitFromEntity(const Entity& entity);
|
||||
|
||||
/**
|
||||
* Add components to entity and set their properties. Calls Finished().
|
||||
*/
|
||||
bool Spawn(Entity& entity) const;
|
||||
|
||||
/**
|
||||
* Copy value from newval to a component property
|
||||
*/
|
||||
bool SetValue(ComponentType ctype, StringId propname, const Property& newval);
|
||||
|
||||
/**
|
||||
* Return true if spawner contains a component of this type
|
||||
*/
|
||||
bool HasComponent(ComponentType ctype) const;
|
||||
|
||||
/**
|
||||
* Return true if spawner or one of its parents contain a component of this type
|
||||
*/
|
||||
bool HasComponentRecursive(ComponentType ctype) const;
|
||||
|
||||
/**
|
||||
* Add a component of type ctype. The props container holds the initial property
|
||||
* values to assign to the component.
|
||||
*/
|
||||
void AddComponent(ComponentType ctype, const GroupProperty& props);
|
||||
|
||||
/**
|
||||
* Remove component of this type. Return true if component existed
|
||||
*/
|
||||
bool RemoveComponent(ComponentType ctype);
|
||||
|
||||
/**
|
||||
* Get property values to assign to component after spawning it
|
||||
*/
|
||||
GroupProperty GetComponentValues(ComponentType ctype) const;
|
||||
|
||||
/**
|
||||
* Set properties of existing component in spawner.The props container holds the initial property
|
||||
* values to assign to the component. All previous component values are cleared.
|
||||
*/
|
||||
void SetComponentValues(ComponentType ctype, const GroupProperty&);
|
||||
|
||||
/**
|
||||
* Get a map of components and their properties set for this spawner
|
||||
*/
|
||||
void GetAllComponentProperties(ComponentProperties& props) const;
|
||||
|
||||
/**
|
||||
* Get component properties of spawner hierarchy, children values overwrite
|
||||
* parent values
|
||||
*/
|
||||
void GetAllComponentPropertiesRecursive(ComponentProperties& props) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Spawner();
|
||||
|
||||
private:
|
||||
|
||||
// name of spawner
|
||||
std::string mName;
|
||||
|
||||
// name of map this spawner was loaded from
|
||||
std::string mMapName;
|
||||
|
||||
// icon for representing spawner in GUI
|
||||
std::string mIconPath;
|
||||
|
||||
// should spawner show up in spawner drag & drop GUI?
|
||||
bool mAddToSpawnerStore;
|
||||
|
||||
// category for spawner store
|
||||
std::string mGUICategory;
|
||||
|
||||
// parent spawner, may be empty
|
||||
osg::ref_ptr<Spawner> mParent;
|
||||
|
||||
// The components and their properties that should be spawned
|
||||
ComponentProperties mComponentProperties;
|
||||
};
|
||||
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <string>
|
||||
#include <dtEntity/dtentity_config.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
// serial ID for strings
|
||||
|
||||
#if DTENTITY_USE_STRINGS_AS_STRINGIDS
|
||||
typedef std::string StringId;
|
||||
#else
|
||||
typedef unsigned int StringId;
|
||||
#endif
|
||||
|
||||
// type id for messages
|
||||
typedef StringId MessageType;
|
||||
|
||||
// type id for components
|
||||
typedef StringId ComponentType;
|
||||
|
||||
/**
|
||||
* Get a unique StringId for given string.
|
||||
* If DTENTITY_USE_STRINGS_AS_STRINGIDS macri is set to ON
|
||||
* this returns the string itself. Else a CRC32 hash
|
||||
* is returned.
|
||||
* In any case, the crc32 value is added to a reverse lookup table
|
||||
* so that it can be resolved back to a string.
|
||||
* This function is thread safe.
|
||||
* @param str The string to index
|
||||
*/
|
||||
StringId DT_ENTITY_EXPORT SID(const std::string& str);
|
||||
|
||||
/**
|
||||
* Get the string that was used to generate the String id.
|
||||
* If DTENTITY_USE_STRINGS_AS_STRINGIDS macro is set
|
||||
* the input string is returned unchanged. Else
|
||||
* a crc32 value is expected as input.
|
||||
*/
|
||||
std::string DT_ENTITY_EXPORT GetStringFromSID(StringId id);
|
||||
|
||||
/**
|
||||
* get string id crc32 hash of string, don't add to reverse lookup
|
||||
*/
|
||||
StringId DT_ENTITY_EXPORT SIDHash(const std::string& str);
|
||||
|
||||
/**
|
||||
* get string id crc32 hash of string, add to reverse lookup
|
||||
*/
|
||||
StringId DT_ENTITY_EXPORT SID(unsigned int hash);
|
||||
|
||||
unsigned int DT_ENTITY_EXPORT SIDToUInt(StringId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
typedef __int64 Timer_t;
|
||||
#else
|
||||
typedef unsigned long long Timer_t;
|
||||
#endif
|
||||
|
||||
class SystemInterface
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~SystemInterface() {}
|
||||
|
||||
/**
|
||||
* Send tick messages to main message pump, also emit
|
||||
* all queued messages
|
||||
*/
|
||||
virtual void EmitTickMessagesAndQueuedMessages() = 0;
|
||||
|
||||
/**
|
||||
* Send PostUpdateMessage to main message pump
|
||||
*/
|
||||
virtual void EmitPostUpdateMessage() = 0;
|
||||
|
||||
/**
|
||||
* Get simulation time delta since last tick in seconds
|
||||
*/
|
||||
virtual float GetDeltaSimTime() const = 0;
|
||||
|
||||
/**
|
||||
* Get real time delta since last tick in seconds
|
||||
*/
|
||||
virtual float GetDeltaRealTime() const = 0;
|
||||
|
||||
/**
|
||||
* Get scaling value from real time to simulation time
|
||||
*/
|
||||
virtual float GetTimeScale() const = 0;
|
||||
|
||||
/**
|
||||
* Set scaling value from real time to simulation time.
|
||||
* A value of 2 means simulation runs twice as fast as real time
|
||||
* Causes a TimeChangedMessage to be sent
|
||||
*/
|
||||
virtual void SetTimeScale(float) = 0;
|
||||
|
||||
/**
|
||||
* Get number of seconds since start of simulation
|
||||
*/
|
||||
virtual double GetSimulationTime() const = 0;
|
||||
|
||||
/**
|
||||
* Set number of seconds since start of simulation
|
||||
* Causes a TimeChangedMessage to be sent
|
||||
*/
|
||||
virtual void SetSimulationTime(double) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Number of microseconds since 1.1.1970
|
||||
* Causes a TimeChangedMessage to be sent
|
||||
*/
|
||||
virtual void SetSimulationClockTime(Timer_t) = 0;
|
||||
|
||||
/**
|
||||
* Get number of microseconds since 1/1/1970
|
||||
*/
|
||||
virtual Timer_t GetSimulationClockTime() const = 0;
|
||||
|
||||
/**
|
||||
* Get current system time in number of microseconds since 1/1/1970
|
||||
*/
|
||||
virtual Timer_t GetRealClockTime() = 0;
|
||||
|
||||
/**
|
||||
* Get absolute path from a relative file path.
|
||||
* Returns empty string if file is not found
|
||||
*/
|
||||
virtual std::string FindDataFile(const std::string& filename) = 0;
|
||||
|
||||
/**
|
||||
* return true if a file exists
|
||||
*/
|
||||
virtual bool FileExists(const std::string& filename) = 0;
|
||||
|
||||
virtual int GetArgC() = 0;
|
||||
virtual const char** GetArgV() = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
+994
@@ -0,0 +1,994 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <osg/Timer>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* These messages are sent by dtEntity subsystems like map or application. User code can
|
||||
* register itself to these messages and react to them. In most cases, user code should not have
|
||||
* to send
|
||||
* these messages.
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class MessageFactory;
|
||||
|
||||
/**
|
||||
* Adds all messages to message factory
|
||||
*/
|
||||
void DT_ENTITY_EXPORT RegisterSystemMessages(MessageFactory&);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Tick message gets sent each frame by the system.
|
||||
* Register for this message if you want to continually update something.
|
||||
* Messages in the message queue are posted after the tick message
|
||||
*/
|
||||
class DT_ENTITY_EXPORT TickMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
// type identifier of this message class
|
||||
static const MessageType TYPE;
|
||||
|
||||
// string identifiers for parameter names
|
||||
static const StringId DeltaSimTimeId;
|
||||
static const StringId DeltaRealTimeId;
|
||||
static const StringId SimTimeScaleId;
|
||||
static const StringId SimulationTimeId;
|
||||
|
||||
// Constructor
|
||||
TickMessage();
|
||||
TickMessage(MessageType t);
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<TickMessage>(); }
|
||||
|
||||
// getters (you could do GetFloat(TickMessage::DeltaSimTimeId) instead)
|
||||
float GetDeltaSimTime() const { return mDeltaSimTime.Get(); }
|
||||
float GetDeltaRealTime() const { return mDeltaRealTime.Get(); }
|
||||
float GetSimTimeScale() const { return mSimTimeScale.Get(); }
|
||||
double GetSimulationTime() const { return mSimulationTime.Get(); }
|
||||
|
||||
void SetDeltaSimTime(float v) { mDeltaSimTime.Set(v); }
|
||||
void SetDeltaRealTime(float v) { mDeltaRealTime.Set(v); }
|
||||
void SetSimTimeScale(float v) { mSimTimeScale.Set(v); }
|
||||
void SetSimulationTime(double v) { mSimulationTime.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
FloatProperty mDeltaSimTime;
|
||||
FloatProperty mDeltaRealTime;
|
||||
FloatProperty mSimTimeScale;
|
||||
DoubleProperty mSimulationTime;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* This message gets sent when a camera component is created.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT CameraAddedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId ContextIdId;
|
||||
|
||||
CameraAddedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<CameraAddedMessage>(); }
|
||||
|
||||
EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); }
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); }
|
||||
|
||||
void SetContextId(unsigned int v) { mContextId.Set(v); }
|
||||
unsigned int GetContextId() const { return mContextId.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntityId;
|
||||
dtEntity::UIntProperty mContextId;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* This message gets sent when a camera component is deleted.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT CameraRemovedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
CameraRemovedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<CameraRemovedMessage>(); }
|
||||
|
||||
EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); }
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntityId;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when a window is to be closed, triggered by WindowManager::CloseWindow.
|
||||
* used internally to asynchronously close window
|
||||
*/
|
||||
class DT_ENTITY_EXPORT InternalCloseWindowMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
// type identifier of this message class
|
||||
static const MessageType TYPE;
|
||||
static const StringId NameId;
|
||||
|
||||
InternalCloseWindowMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual dtEntity::Message* Clone() const { return CloneContainer<InternalCloseWindowMessage>(); }
|
||||
|
||||
void SetName(const std::string& v) { mName.Set(v); }
|
||||
std::string GetName() const { return mName.Get(); }
|
||||
|
||||
private:
|
||||
dtEntity::StringProperty mName;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* EndOfFrameMessage gets sent after TickMessage and after messages in
|
||||
* the message queue are emitted.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EndOfFrameMessage
|
||||
: public TickMessage
|
||||
{
|
||||
public:
|
||||
static const MessageType TYPE;
|
||||
|
||||
EndOfFrameMessage();
|
||||
virtual Message* Clone() const { return CloneContainer<EndOfFrameMessage>(); }
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* PostUpdateMessage gets sent after scene graph update traversal
|
||||
*/
|
||||
class DT_ENTITY_EXPORT PostUpdateMessage
|
||||
: public TickMessage
|
||||
{
|
||||
public:
|
||||
static const MessageType TYPE;
|
||||
|
||||
PostUpdateMessage();
|
||||
virtual Message* Clone() const { return CloneContainer<PostUpdateMessage>(); }
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* This message gets sent when the method EntityManager::AddToScene method is
|
||||
* called. The layer system reacts to this message by attaching the entity to the scene
|
||||
* graph.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntityAddedToSceneMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId EntityNameId;
|
||||
static const StringId UniqueIdId;
|
||||
static const StringId MapNameId;
|
||||
static const StringId VisibleInEntityListId;
|
||||
|
||||
EntityAddedToSceneMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<EntityAddedToSceneMessage>(); }
|
||||
|
||||
EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); }
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); }
|
||||
|
||||
std::string GetEntityName() const { return mEntityName.Get(); }
|
||||
void SetEntityName(const std::string& v) { mEntityName.Set(v); }
|
||||
|
||||
std::string GetUniqueId() const { return mUniqueId.Get(); }
|
||||
void SetUniqueId(const std::string& v) { mUniqueId.Set(v); }
|
||||
|
||||
std::string GetMapName() const { return mMapName.Get(); }
|
||||
void SetMapName(const std::string& v) { mMapName.Set(v); }
|
||||
|
||||
bool GetVisibleInEntityList() const { return mVisibleInEntityList.Get(); }
|
||||
void SetVisibleInEntityList(bool v) { mVisibleInEntityList.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntityId;
|
||||
StringProperty mEntityName;
|
||||
StringProperty mUniqueId;
|
||||
StringProperty mMapName;
|
||||
BoolProperty mVisibleInEntityList;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when an entity was removed from the selection
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntityDeselectedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
|
||||
EntityDeselectedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<EntityDeselectedMessage>(); }
|
||||
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); }
|
||||
EntityId GetAboutEntityId() const { return mAboutEntity.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntity;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when name or unique id of entity is changed
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntityNameUpdatedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId EntityNameId;
|
||||
static const StringId UniqueIdId;
|
||||
|
||||
EntityNameUpdatedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<EntityNameUpdatedMessage>(); }
|
||||
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); }
|
||||
EntityId GetAboutEntityId() const { return mAboutEntity.Get(); }
|
||||
|
||||
void SetEntityName(const std::string& v) { mEntityName.Set(v); }
|
||||
std::string GetEntityName() const { return mEntityName.Get(); }
|
||||
|
||||
void SetUniqueId(const std::string& v) { mUniqueId.Set(v); }
|
||||
std::string GetUniqueId() const { return mUniqueId.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntity;
|
||||
StringProperty mEntityName;
|
||||
StringProperty mUniqueId;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* This message gets sent when the method EntityManager::RemoveFromScene method is
|
||||
* called. The layer system reacts to this message by removing the entity from the scene
|
||||
* graph.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntityRemovedFromSceneMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId EntityNameId;
|
||||
static const StringId UniqueIdId;
|
||||
static const StringId MapNameId;
|
||||
static const StringId VisibleInEntityListId;
|
||||
|
||||
EntityRemovedFromSceneMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<EntityRemovedFromSceneMessage>(); }
|
||||
|
||||
EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); }
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); }
|
||||
|
||||
std::string GetEntityName() const { return mEntityName.Get(); }
|
||||
void SetEntityName(const std::string& v) { mEntityName.Set(v); }
|
||||
|
||||
std::string GetUniqueId() const { return mUniqueId.Get(); }
|
||||
void SetUniqueId(const std::string& v) { mUniqueId.Set(v); }
|
||||
|
||||
std::string GetMapName() const { return mMapName.Get(); }
|
||||
void SetMapName(const std::string& v) { mMapName.Set(v); }
|
||||
|
||||
bool GetVisibleInEntityList() const { return mVisibleInEntityList.Get(); }
|
||||
void SetVisibleInEntityList(bool v) { mVisibleInEntityList.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntityId;
|
||||
StringProperty mEntityName;
|
||||
StringProperty mUniqueId;
|
||||
StringProperty mMapName;
|
||||
BoolProperty mVisibleInEntityList;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when an entity was added to the selection
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntitySelectedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
|
||||
EntitySelectedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<EntitySelectedMessage>(); }
|
||||
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); }
|
||||
EntityId GetAboutEntityId() const { return mAboutEntity.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntity;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when an entity was added to the selection
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntitySpawnedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId SpawnerNameId;
|
||||
|
||||
EntitySpawnedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<EntitySpawnedMessage>(); }
|
||||
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); }
|
||||
EntityId GetAboutEntityId() const { return mAboutEntity.Get(); }
|
||||
|
||||
void SetSpawnerName(const std::string& name) { mSpawnerName.Set(name); }
|
||||
std::string GetSpawnerName() const { return mSpawnerName.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntity;
|
||||
StringProperty mSpawnerName;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when an entity system is added to the entity manager.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntitySystemAddedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId ComponentTypeId;
|
||||
static const StringId ComponentTypeStringId;
|
||||
|
||||
EntitySystemAddedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<EntitySystemAddedMessage>(); }
|
||||
|
||||
StringId GetComponentType() const { return mComponentType.Get(); }
|
||||
void SetComponentType(StringId v) { mComponentType.Set(v); }
|
||||
|
||||
std::string GetComponentTypeString() const { return mComponentTypeString.Get(); }
|
||||
void SetComponentTypeString(const std::string& v) { mComponentTypeString.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringIdProperty mComponentType;
|
||||
StringProperty mComponentTypeString;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when an entity system is removed from the entity manager.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntitySystemRemovedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId ComponentTypeId;
|
||||
static const StringId ComponentTypeStringId;
|
||||
|
||||
EntitySystemRemovedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<EntitySystemRemovedMessage>(); }
|
||||
|
||||
StringId GetComponentType() const { return mComponentType.Get(); }
|
||||
void SetComponentType(StringId v) { mComponentType.Set(v); }
|
||||
|
||||
std::string GetComponentTypeString() const { return mComponentTypeString.Get(); }
|
||||
void SetComponentTypeString(const std::string& v) { mComponentTypeString.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringIdProperty mComponentType;
|
||||
StringProperty mComponentTypeString;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when name or unique id of entity is changed
|
||||
*/
|
||||
class DT_ENTITY_EXPORT EntityVelocityNotNullMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId IsNullId;
|
||||
|
||||
EntityVelocityNotNullMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual Message* Clone() const { return CloneContainer<EntityVelocityNotNullMessage>(); }
|
||||
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); }
|
||||
EntityId GetAboutEntityId() const { return mAboutEntity.Get(); }
|
||||
|
||||
void SetIsNull(bool v) { mIsNull.Set(v); }
|
||||
bool GetIsNull() const { return mIsNull.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntity;
|
||||
BoolProperty mIsNull;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent before a map is loaded
|
||||
*/
|
||||
class DT_ENTITY_EXPORT MapBeginLoadMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId MapPathId;
|
||||
static const StringId DataPathId;
|
||||
static const StringId SaveOrderId;
|
||||
|
||||
MapBeginLoadMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<MapBeginLoadMessage>(); }
|
||||
|
||||
std::string GetMapPath() const { return mMapPath.Get(); }
|
||||
void SetMapPath(const std::string& v){ mMapPath.Set(v); }
|
||||
|
||||
std::string GetDataPath() const { return mDataPath.Get(); }
|
||||
void SetDataPath(const std::string& v){ mDataPath.Set(v); }
|
||||
|
||||
unsigned int GetSaveOrder() const { return mSaveOrder.Get(); }
|
||||
void SetSaveOrder(unsigned int v){ mSaveOrder.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mMapPath;
|
||||
StringProperty mDataPath;
|
||||
UIntProperty mSaveOrder;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when a map is about to be unloaded
|
||||
*/
|
||||
class DT_ENTITY_EXPORT MapBeginUnloadMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId MapPathId;
|
||||
|
||||
MapBeginUnloadMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<MapBeginUnloadMessage>(); }
|
||||
|
||||
std::string GetMapPath() const { return mMapPath.Get(); }
|
||||
void SetMapPath(const std::string& v){ mMapPath.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mMapPath;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when a map was loaded
|
||||
*/
|
||||
class DT_ENTITY_EXPORT MapLoadedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId MapPathId;
|
||||
static const StringId DataPathId;
|
||||
static const StringId SaveOrderId;
|
||||
|
||||
MapLoadedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<MapLoadedMessage>(); }
|
||||
|
||||
std::string GetMapPath() const { return mMapPath.Get(); }
|
||||
void SetMapPath(const std::string& v){ mMapPath.Set(v); }
|
||||
|
||||
std::string GetDataPath() const { return mDataPath.Get(); }
|
||||
void SetDataPath(const std::string& v){ mDataPath.Set(v); }
|
||||
|
||||
unsigned int GetSaveOrder() const { return mSaveOrder.Get(); }
|
||||
void SetSaveOrder(unsigned int v){ mSaveOrder.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mMapPath;
|
||||
StringProperty mDataPath;
|
||||
UIntProperty mSaveOrder;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when a map was unloaded
|
||||
*/
|
||||
class DT_ENTITY_EXPORT MapUnloadedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId MapPathId;
|
||||
|
||||
MapUnloadedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<MapUnloadedMessage>(); }
|
||||
|
||||
std::string GetMapPath() const { return mMapPath.Get(); }
|
||||
void SetMapPath(const std::string& v){ mMapPath.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mMapPath;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Emitted when mesh of an entity is changed.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT MeshChangedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId FilePathId;
|
||||
|
||||
MeshChangedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<MeshChangedMessage>(); }
|
||||
|
||||
EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); }
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); }
|
||||
|
||||
std::string GetFilePath() const { return mFilePath.Get(); }
|
||||
void SetFilePath(const std::string& id) { mFilePath.Set(id); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntityId;
|
||||
StringProperty mFilePath;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when a watched resource was changed on disk
|
||||
*/
|
||||
class DT_ENTITY_EXPORT ResourceChangedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
// type identifier of this message class
|
||||
static const MessageType TYPE;
|
||||
static const StringId PathId;
|
||||
|
||||
ResourceChangedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual dtEntity::Message* Clone() const { return CloneContainer<ResourceChangedMessage>(); }
|
||||
|
||||
void SetPath(const std::string& v) { mPath.Set(v); }
|
||||
std::string GetPath() const { return mPath.Get(); }
|
||||
|
||||
private:
|
||||
dtEntity::StringProperty mPath;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when a watched resource was changed on disk
|
||||
*/
|
||||
class DT_ENTITY_EXPORT ResourceLoadedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
// type identifier of this message class
|
||||
static const MessageType TYPE;
|
||||
static const StringId PathId;
|
||||
|
||||
ResourceLoadedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual dtEntity::Message* Clone() const { return CloneContainer<ResourceLoadedMessage>(); }
|
||||
|
||||
void SetPath(const std::string& v) { mPath.Set(v); }
|
||||
std::string GetPath() const { return mPath.Get(); }
|
||||
|
||||
private:
|
||||
dtEntity::StringProperty mPath;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when a scene was loaded
|
||||
*/
|
||||
class DT_ENTITY_EXPORT SceneLoadedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId SceneNameId;
|
||||
|
||||
SceneLoadedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<SceneLoadedMessage>(); }
|
||||
|
||||
std::string GetSceneName() const { return mSceneName.Get(); }
|
||||
void SetSceneName(const std::string& v){ mSceneName.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mSceneName;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when a scene was unloaded
|
||||
*/
|
||||
class DT_ENTITY_EXPORT SceneUnloadedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
SceneUnloadedMessage();
|
||||
virtual Message* Clone() const { return CloneContainer<SceneUnloadedMessage>(); }
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when a spawner was added to the map system
|
||||
*/
|
||||
class DT_ENTITY_EXPORT SpawnerAddedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId MapNameId;
|
||||
static const StringId NameId;
|
||||
static const StringId ParentNameId;
|
||||
|
||||
SpawnerAddedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<SpawnerAddedMessage>(); }
|
||||
|
||||
std::string GetMapName() const { return mMapName.Get(); }
|
||||
void SetMapName(const std::string& v){ mMapName.Set(v); }
|
||||
|
||||
std::string GetName() const { return mName.Get(); }
|
||||
void SetName(const std::string& v){ mName.Set(v); }
|
||||
|
||||
std::string GetParentName() const { return mParentName.Get(); }
|
||||
void SetParentName(const std::string& v){ mParentName.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mName;
|
||||
StringProperty mParentName;
|
||||
StringProperty mMapName;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when a spawner was modified
|
||||
*/
|
||||
class DT_ENTITY_EXPORT SpawnerModifiedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId OldCategoryId;
|
||||
static const StringId NewCategoryId;
|
||||
static const StringId NameId;
|
||||
static const StringId MapNameId;
|
||||
|
||||
SpawnerModifiedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<SpawnerModifiedMessage>(); }
|
||||
|
||||
std::string GetName() const { return mName.Get(); }
|
||||
void SetName(const std::string& v){ mName.Set(v); }
|
||||
|
||||
std::string GetMapName() const { return mMapName.Get(); }
|
||||
void SetMapName(const std::string& v){ mMapName.Set(v); }
|
||||
|
||||
std::string GetOldCategory() const { return mOldCategory.Get(); }
|
||||
void SetOldCategory(const std::string& v){ mOldCategory.Set(v); }
|
||||
|
||||
std::string GetNewCategory() const { return mNewCategory.Get(); }
|
||||
void SetNewCategory(const std::string& v){ mNewCategory.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mName;
|
||||
StringProperty mMapName;
|
||||
StringProperty mOldCategory;
|
||||
StringProperty mNewCategory;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Gets sent when a spawner was removed from the map system
|
||||
*/
|
||||
class DT_ENTITY_EXPORT SpawnerRemovedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId MapNameId;
|
||||
static const StringId NameId;
|
||||
static const StringId CategoryId;
|
||||
|
||||
SpawnerRemovedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<SpawnerRemovedMessage>(); }
|
||||
|
||||
std::string GetMapName() const { return mMapName.Get(); }
|
||||
void SetMapName(const std::string& v){ mMapName.Set(v); }
|
||||
|
||||
std::string GetName() const { return mName.Get(); }
|
||||
void SetName(const std::string& v){ mName.Set(v); }
|
||||
|
||||
std::string GetCategory() const { return mCategory.Get(); }
|
||||
void SetCategory(const std::string& v){ mCategory.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
StringProperty mName;
|
||||
StringProperty mMapName;
|
||||
StringProperty mCategory;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when entering simulation loop
|
||||
*/
|
||||
class DT_ENTITY_EXPORT StartSystemMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
|
||||
StartSystemMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<StartSystemMessage>(); }
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when entering simulation loop
|
||||
*/
|
||||
class DT_ENTITY_EXPORT StopSystemMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
|
||||
StopSystemMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<StopSystemMessage>(); }
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when the EntityManager::ChangeTimeSettings method is called.
|
||||
*/
|
||||
class DT_ENTITY_EXPORT TimeChangedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId SimulationTimeId;
|
||||
static const StringId SimulationClockTimeId;
|
||||
static const StringId TimeScaleId;
|
||||
|
||||
TimeChangedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<TimeChangedMessage>(); }
|
||||
|
||||
float GetTimeScale() const { return mTimeScale.Get(); }
|
||||
void SetTimeScale(float v) { mTimeScale.Set(v); }
|
||||
|
||||
osg::Timer_t GetSimulationClockTime() const { return mSimulationClockTime; }
|
||||
void SetSimulationClockTime(osg::Timer_t v) { mSimulationClockTime = v; }
|
||||
|
||||
double GetSimulationTime() const { return mSimulationTime.Get(); }
|
||||
void SetSimulationTime(double v) { mSimulationTime.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
DoubleProperty mSimulationTime;
|
||||
osg::Timer_t mSimulationClockTime;
|
||||
FloatProperty mTimeScale;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Emitted when entity is shown/hidden
|
||||
*/
|
||||
class DT_ENTITY_EXPORT VisibilityChangedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
static const MessageType TYPE;
|
||||
static const StringId AboutEntityId;
|
||||
static const StringId VisibleId;
|
||||
|
||||
VisibilityChangedMessage();
|
||||
|
||||
virtual Message* Clone() const { return CloneContainer<VisibilityChangedMessage>(); }
|
||||
|
||||
EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); }
|
||||
void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); }
|
||||
|
||||
bool GetVisible() const { return mVisible.Get(); }
|
||||
void SetVisible(bool v) { mVisible.Set(v); }
|
||||
|
||||
private:
|
||||
|
||||
UIntProperty mAboutEntityId;
|
||||
BoolProperty mVisible;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when a window was opened with WindowManager::OpenWindow
|
||||
*/
|
||||
class DT_ENTITY_EXPORT WindowCreatedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
// type identifier of this message class
|
||||
static const MessageType TYPE;
|
||||
static const StringId NameId;
|
||||
static const StringId ContextIdId;
|
||||
static const StringId CameraEntityIdId;
|
||||
|
||||
WindowCreatedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual dtEntity::Message* Clone() const { return CloneContainer<WindowCreatedMessage>(); }
|
||||
|
||||
void SetName(const std::string& v) { mName.Set(v); }
|
||||
std::string GetName() const { return mName.Get(); }
|
||||
|
||||
void SetContextId(unsigned int v) { mContextId.Set(v); }
|
||||
unsigned int GetContextId() const { return mContextId.Get(); }
|
||||
|
||||
void SetCameraEntityId(unsigned int v) { mCameraEntityId.Set(v); }
|
||||
unsigned int GetCameraEntityId() const { return mCameraEntityId.Get(); }
|
||||
|
||||
private:
|
||||
dtEntity::StringProperty mName;
|
||||
dtEntity::UIntProperty mContextId;
|
||||
dtEntity::UIntProperty mCameraEntityId;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Is sent when a window was closed
|
||||
*/
|
||||
class DT_ENTITY_EXPORT WindowClosedMessage
|
||||
: public Message
|
||||
{
|
||||
public:
|
||||
|
||||
// type identifier of this message class
|
||||
static const MessageType TYPE;
|
||||
static const StringId NameId;
|
||||
|
||||
WindowClosedMessage();
|
||||
|
||||
// Create a copy of this message on the heap
|
||||
virtual dtEntity::Message* Clone() const { return CloneContainer<WindowClosedMessage>(); }
|
||||
|
||||
void SetName(const std::string& v) { mName.Set(v); }
|
||||
std::string GetName() const { return mName.Get(); }
|
||||
|
||||
private:
|
||||
dtEntity::StringProperty mName;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <queue>
|
||||
#include <OpenThreads/Mutex>
|
||||
#include <OpenThreads/ScopedLock>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
/**
|
||||
* A queue with thread safe push and pop methods
|
||||
*/
|
||||
template<class T>
|
||||
class ThreadSafeQueue
|
||||
{
|
||||
public:
|
||||
|
||||
void Push(T t);
|
||||
bool Empty();
|
||||
T Pop();
|
||||
unsigned int GetSize();
|
||||
|
||||
private:
|
||||
|
||||
OpenThreads::Mutex mQueueMutex;
|
||||
std::queue<T> mQueue;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
|
||||
template<class T>
|
||||
void ThreadSafeQueue<T>::Push(T t)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mQueueMutex);
|
||||
mQueue.push(t);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool ThreadSafeQueue<T>::Empty()
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mQueueMutex);
|
||||
return mQueue.empty();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T ThreadSafeQueue<T>::Pop()
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mQueueMutex);
|
||||
if(mQueue.empty()) return T();
|
||||
T t = mQueue.front();
|
||||
mQueue.pop();
|
||||
return t;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
unsigned int ThreadSafeQueue<T>::GetSize()
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mQueueMutex);
|
||||
return mQueue.size();
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/export.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
std::string DT_ENTITY_EXPORT CreateUniqueIdString();
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/nodemasks.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class WindowInterface
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~WindowInterface() {}
|
||||
|
||||
/**
|
||||
* Opens a new window if used viewer is a composite viewer.
|
||||
* @param name Name of osg nodes for window, view and camera to set
|
||||
* @param traits OSG GraphicsWindow traits to use
|
||||
* @contexId will receive context id of newly created context
|
||||
* @return true if success
|
||||
*/
|
||||
virtual bool OpenWindow(const std::string& name, unsigned int& contextId) = 0;
|
||||
|
||||
virtual void CloseWindow(unsigned int contextid) = 0;
|
||||
|
||||
/**
|
||||
* Get pick ray at given screen position
|
||||
* @param usePixels if true, use x-y screen coordinates, if false use values from -1 to 1
|
||||
*/
|
||||
virtual Vec3f GetPickRay(unsigned int contextid, float x, float y, bool usePixels = false) const = 0;
|
||||
|
||||
/**
|
||||
Get window size and position of window with given context id
|
||||
*/
|
||||
virtual bool GetWindowGeometry(unsigned int contextid, int& x, int& y, int& width, int& height) const = 0;
|
||||
|
||||
/**
|
||||
Set window size and position of window with given context id
|
||||
*/
|
||||
virtual bool SetWindowGeometry(unsigned int contextid, int x, int y, int width, int height) = 0;
|
||||
|
||||
/**
|
||||
Should window be displayed at full screen size?
|
||||
*/
|
||||
virtual void SetFullscreen(unsigned int contextid, bool fullscreen) = 0;
|
||||
virtual bool GetFullscreen(unsigned int contextid) const = 0;
|
||||
|
||||
/**
|
||||
* Return entity id of first intersected entity.
|
||||
*/
|
||||
virtual EntityId PickEntity(double x, double y, unsigned int nodemask,
|
||||
unsigned int contextid, bool usePixels = true) const = 0;
|
||||
|
||||
/**
|
||||
* Show or hide cursor when it is above this window?
|
||||
*/
|
||||
virtual void SetShowCursor(unsigned int contextid, bool) = 0;
|
||||
|
||||
/**
|
||||
* project world space point into screen coordinates
|
||||
*/
|
||||
virtual Vec3d ConvertWorldToScreenCoords(unsigned int contextid, const Vec3d& coord) = 0;
|
||||
|
||||
/**
|
||||
* Should the window with given context id be continuously redrawn
|
||||
* or only by request? Default is on
|
||||
*/
|
||||
virtual void SetContinuousRedraw(unsigned int contextid, bool) = 0;
|
||||
|
||||
/**
|
||||
* If Continuous Redraw is off, request a redraw in next render traversal
|
||||
*/
|
||||
virtual void RequestRedraw(unsigned int contextid) = 0;
|
||||
|
||||
/**
|
||||
* Holds intersection info
|
||||
*/
|
||||
struct Intersection
|
||||
{
|
||||
Vec3d mPosition;
|
||||
Vec3f mNormal;
|
||||
EntityId mEntityId;
|
||||
};
|
||||
|
||||
typedef std::vector<Intersection> Intersections;
|
||||
|
||||
/**
|
||||
* Get intersections between start and end and add them to isects vector
|
||||
* @param start Start of intersection line
|
||||
* @param end End of intersection lnie
|
||||
* @param isects Vector return value for isect results
|
||||
* @param nodemask Bit mask, used for selecting nodes for intersection
|
||||
* @param layer Name of layer attach point component from which intersecition test will
|
||||
* be executed downwards (default: layer "default")
|
||||
* @return true if an intersection was found
|
||||
*/
|
||||
virtual bool GetIntersections(const Vec3d& start, const Vec3d& end,
|
||||
std::vector<Intersection>& isects,
|
||||
unsigned int nodemask = NodeMasks::PICKABLE | NodeMasks::TERRAIN,
|
||||
dtEntity::StringId layer = dtEntity::StringId()
|
||||
) const = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/transformcomponent.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Group;
|
||||
class Camera;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
/**
|
||||
* The camera component holds properties for the osg::Camera object
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT CameraComponent
|
||||
: public TransformComponent
|
||||
{
|
||||
|
||||
typedef TransformComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId ContextIdId;
|
||||
static const dtEntity::StringId LayerAttachPointId;
|
||||
|
||||
static const dtEntity::StringId CullingModeId;
|
||||
static const dtEntity::StringId CullMaskId;
|
||||
static const dtEntity::StringId NoAutoNearFarCullingId;
|
||||
static const dtEntity::StringId BoundingVolumeNearFarCullingId;
|
||||
static const dtEntity::StringId PrimitiveNearFarCullingId;
|
||||
static const dtEntity::StringId FieldOfViewId;
|
||||
static const dtEntity::StringId AspectRatioId;
|
||||
static const dtEntity::StringId NearClipId;
|
||||
static const dtEntity::StringId FarClipId;
|
||||
static const dtEntity::StringId LODScaleId;
|
||||
static const dtEntity::StringId ClearColorId;
|
||||
static const dtEntity::StringId PositionId;
|
||||
static const dtEntity::StringId EyeDirectionId;
|
||||
static const dtEntity::StringId UpId;
|
||||
|
||||
static const dtEntity::StringId OrthoLeftId;
|
||||
static const dtEntity::StringId OrthoRightId;
|
||||
static const dtEntity::StringId OrthoTopId;
|
||||
static const dtEntity::StringId OrthoBottomId;
|
||||
static const dtEntity::StringId OrthoZNearId;
|
||||
static const dtEntity::StringId OrthoZFarId;
|
||||
|
||||
static const dtEntity::StringId ProjectionModeId;
|
||||
static const dtEntity::StringId ModePerspectiveId;
|
||||
static const dtEntity::StringId ModeOrthoId;
|
||||
|
||||
CameraComponent();
|
||||
|
||||
virtual ~CameraComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
virtual void OnRemovedFromEntity(dtEntity::Entity& entity);
|
||||
|
||||
osg::Camera* GetCamera() const;
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void FetchCamera();
|
||||
|
||||
void SetContextId(int id);
|
||||
int GetContextId() const { return mContextIdVal; }
|
||||
|
||||
void SetLayerAttachPoint(dtEntity::StringId id);
|
||||
dtEntity::StringId GetLayerAttachPoint() const;
|
||||
|
||||
void SetProjectionMode(dtEntity::StringId);
|
||||
dtEntity::StringId GetProjectionMode() const { return mProjectionModeVal; }
|
||||
|
||||
void SetCullingMode(dtEntity::StringId);
|
||||
dtEntity::StringId GetCullingMode() const { return mCullingModeVal; }
|
||||
|
||||
/** Set up vector of camera. Call UpdateViewMatrix to apply changes. */
|
||||
void SetUp(const osg::Vec3d&);
|
||||
osg::Vec3d GetUp() const;
|
||||
|
||||
/** Set eye position of camera. Call UpdateViewMatrix to apply changes. */
|
||||
void SetPosition(const osg::Vec3d&);
|
||||
osg::Vec3d GetPosition() const;
|
||||
|
||||
/** Set look direction of camera. Should be a normalized vector!
|
||||
* Call UpdateViewMatrix to apply changes.
|
||||
*/
|
||||
void SetEyeDirection(const osg::Vec3d&);
|
||||
osg::Vec3d GetEyeDirection() const;
|
||||
|
||||
/**
|
||||
* Re-calculate osg camera view matrix from up, pos and eye dir vectors
|
||||
*/
|
||||
void UpdateViewMatrix();
|
||||
|
||||
/**
|
||||
* Re-calculate osg camera projection matrix from mode, near, far etc
|
||||
*/
|
||||
void UpdateProjectionMatrix();
|
||||
|
||||
/**
|
||||
* Set the osg node mask controlling which nodes are
|
||||
* visible to the camera. Please see dtEntity/nodemasks.h
|
||||
*/
|
||||
void SetCullMask(unsigned int mask);
|
||||
unsigned int GetCullMask() const;
|
||||
|
||||
void SetClearColor(const osg::Vec4&);
|
||||
osg::Vec4 GetClearColor() const;
|
||||
|
||||
virtual osg::Vec3d GetTranslation() const { return GetPosition(); }
|
||||
virtual void SetTranslation(const osg::Vec3d& v) { SetPosition(v); }
|
||||
|
||||
virtual osg::Quat GetRotation() const
|
||||
{
|
||||
osg::Quat q;
|
||||
q.makeRotate(osg::Vec3d(0,1,0), mEyeDirection.Get());
|
||||
return q;
|
||||
}
|
||||
|
||||
virtual void SetRotation(const osg::Quat& q)
|
||||
{
|
||||
mEyeDirection.Set(q * osg::Vec3d(0, 1, 0));
|
||||
}
|
||||
|
||||
void SetFieldOfView(double v);
|
||||
double GetFieldOfView() const;
|
||||
|
||||
void SetAspectRatio(double v);
|
||||
double GetAspectRatio() const;
|
||||
|
||||
void SetNearClip(double v);
|
||||
double GetNearClip() const;
|
||||
|
||||
void SetFarClip(double v);
|
||||
double GetFarClip() const;
|
||||
|
||||
void SetLODScale(float v);
|
||||
float GetLODScale() const;
|
||||
|
||||
void SetOrthoLeft(double v);
|
||||
double GetOrthoLeft() const;
|
||||
|
||||
void SetOrthoRight(double v);
|
||||
double GetOrthoRight() const;
|
||||
|
||||
void SetOrthoTop(double v);
|
||||
double GetOrthoTop() const;
|
||||
|
||||
void SetOrthoBottom(double v);
|
||||
double GetOrthoBottom() const;
|
||||
|
||||
void SetOrthoZNear(double v);
|
||||
double GetOrthoZNear() const;
|
||||
|
||||
void SetOrthoZFar(double v);
|
||||
double GetOrthoZFar() const;
|
||||
|
||||
void TryAssignContext();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
dtEntity::DynamicIntProperty mContextId;
|
||||
int mContextIdVal;
|
||||
dtEntity::DynamicStringIdProperty mLayerAttachPoint;
|
||||
dtEntity::StringId mLayerAttachPointVal;
|
||||
|
||||
dtEntity::DynamicStringIdProperty mCullingMode;
|
||||
dtEntity::StringId mCullingModeVal;
|
||||
dtEntity::DynamicDoubleProperty mFieldOfView;
|
||||
double mFieldOfViewVal;
|
||||
dtEntity::DynamicDoubleProperty mAspectRatio;
|
||||
double mAspectRatioVal;
|
||||
dtEntity::DynamicDoubleProperty mNearClip;
|
||||
double mNearClipVal;
|
||||
dtEntity::DynamicDoubleProperty mFarClip;
|
||||
double mFarClipVal;
|
||||
dtEntity::DynamicVec4Property mClearColor;
|
||||
dtEntity::DynamicFloatProperty mLODScale;
|
||||
dtEntity::Vec3dProperty mPosition;
|
||||
dtEntity::Vec3dProperty mUp;
|
||||
dtEntity::Vec3dProperty mEyeDirection;
|
||||
dtEntity::DynamicUIntProperty mCullMask;
|
||||
dtEntity::DynamicStringIdProperty mProjectionMode;
|
||||
dtEntity::StringId mProjectionModeVal;
|
||||
|
||||
dtEntity::DynamicDoubleProperty mOrthoLeft;
|
||||
dtEntity::DynamicDoubleProperty mOrthoRight;
|
||||
dtEntity::DynamicDoubleProperty mOrthoBottom;
|
||||
dtEntity::DynamicDoubleProperty mOrthoTop;
|
||||
dtEntity::DynamicDoubleProperty mOrthoZNear;
|
||||
dtEntity::DynamicDoubleProperty mOrthoZFar;
|
||||
double mOrthoLeftVal;
|
||||
double mOrthoRightVal;
|
||||
double mOrthoBottomVal;
|
||||
double mOrthoTopVal;
|
||||
double mOrthoZNearVal;
|
||||
double mOrthoZFarVal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT CameraSystem
|
||||
: public dtEntity::DefaultEntitySystem<CameraComponent>
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
CameraSystem(dtEntity::EntityManager& em);
|
||||
~CameraSystem();
|
||||
|
||||
dtEntity::EntityId GetCameraEntityByContextId(int id);
|
||||
|
||||
void OnWindowCreated(const dtEntity::Message& msg);
|
||||
|
||||
private:
|
||||
dtEntity::MessageFunctor mWindowCreatedFunctor;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class ComponentPluginManager;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
void DTENTITY_OSG_EXPORT RegisterStandardFactories(dtEntity::ComponentPluginManager& pluginManager);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
// auto-generated by CMake, do not edit!
|
||||
|
||||
// was osgEphemeris found by cmake?
|
||||
#define OSGEPHEMERIS_FOUND 0
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
|
||||
# ifdef DTENTITY_OSG_LIBRARY
|
||||
# define DTENTITY_OSG_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define DTENTITY_OSG_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
# define DTENTITY_OSG_EXPORT
|
||||
#endif
|
||||
@@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/cameracomponent.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/nodemasks.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
#include <osgUtil/IntersectionVisitor>
|
||||
#include <osgUtil/LineSegmentIntersector>
|
||||
#include <osgSim/LineOfSight>
|
||||
#include <osg/observer_ptr>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class MapSystem;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class GroundClampingComponent : public dtEntity::Component
|
||||
{
|
||||
typedef dtEntity::Component BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId ClampingModeId;
|
||||
static const dtEntity::StringId ClampingMode_DisabledId;
|
||||
static const dtEntity::StringId ClampingMode_KeepAboveTerrainId;
|
||||
static const dtEntity::StringId ClampingMode_SetHeightToTerrainHeightId;
|
||||
static const dtEntity::StringId ClampingMode_SetHeightAndRotationToTerrainId;
|
||||
static const dtEntity::StringId MinDistToCameraId;
|
||||
static const dtEntity::StringId MinMovementDeltaId;
|
||||
static const dtEntity::StringId VerticalOffsetId;
|
||||
|
||||
GroundClampingComponent();
|
||||
virtual ~GroundClampingComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& e);
|
||||
virtual void Finished();
|
||||
dtEntityOSG::TransformComponent* GetTransformComponent() const { return mTransformComponent; }
|
||||
|
||||
void SetClampingMode(dtEntity::StringId mode) { mClampingMode.Set(mode); }
|
||||
dtEntity::StringId GetClampingMode() const { return mClampingMode.Get(); }
|
||||
|
||||
float GetVerticalOffset() const { return mVerticalOffset.Get(); }
|
||||
void SetVerticalOffset(float v) { mVerticalOffset.Set(v); }
|
||||
|
||||
// for keeping track of intersections when using osgSim HeightAboveTerrain
|
||||
void SetIntersectIndex(unsigned int i) { mIntersectIndex = i; }
|
||||
unsigned int GetIntersectIndex() const { return mIntersectIndex; }
|
||||
|
||||
osgUtil::LineSegmentIntersector* GetIntersector() const { return mIntersector.get(); }
|
||||
void SetIntersector(osgUtil::LineSegmentIntersector* isect) { mIntersector = isect; }
|
||||
|
||||
void SetLastClampedPosition(const osg::Vec3d& p) { mLastClampedPosition = p; }
|
||||
osg::Vec3d GetLastClampedPosition() const { return mLastClampedPosition; }
|
||||
|
||||
void SetLastClampedAttitude(const osg::Quat& p) { mLastClampedAttitude = p; }
|
||||
osg::Quat GetLastClampedAttitude() const { return mLastClampedAttitude; }
|
||||
|
||||
void SetLastClampedNormal(const osg::Vec3& p) { mLastClampedNormal = p; }
|
||||
osg::Vec3 GetLastClampedNormal() const { return mLastClampedNormal; }
|
||||
|
||||
void SetMinDistToCamera(float p) { mMinDistToCamera.Set(p); }
|
||||
float GetMinDistToCamera() const { return mMinDistToCamera.Get(); }
|
||||
|
||||
void SetMinMovementDelta(float p) { mMinMovementDelta.Set(p); }
|
||||
float GetMinMovementDelta() const { return mMinMovementDelta.Get(); }
|
||||
|
||||
void SetDirty(bool v) { mDirty = v; }
|
||||
bool GetDirty() const { return mDirty; }
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::StringIdProperty mClampingMode;
|
||||
dtEntity::FloatProperty mVerticalOffset;
|
||||
dtEntity::FloatProperty mMinDistToCamera;
|
||||
dtEntity::FloatProperty mMinMovementDelta;
|
||||
|
||||
dtEntityOSG::TransformComponent* mTransformComponent;
|
||||
unsigned int mIntersectIndex;
|
||||
dtEntity::Entity* mEntity;
|
||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> mIntersector;
|
||||
osg::Vec3d mLastClampedPosition;
|
||||
osg::Vec3d mLastClampedNormal;
|
||||
|
||||
bool mDirty;
|
||||
osg::Quat mLastClampedAttitude;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class GroundClampingSystem
|
||||
: public dtEntity::DefaultEntitySystem<GroundClampingComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<GroundClampingComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
static const dtEntity::StringId IntersectLayerId;
|
||||
static const dtEntity::StringId FetchLODsId;
|
||||
|
||||
GroundClampingSystem(dtEntity::EntityManager& em);
|
||||
~GroundClampingSystem();
|
||||
|
||||
void OnRemoveFromEntityManager(dtEntity::EntityManager& em);
|
||||
|
||||
void Tick(const dtEntity::Message& msg);
|
||||
void CameraAdded(const dtEntity::Message& msg);
|
||||
void CameraRemoved(const dtEntity::Message& msg);
|
||||
void MapLoaded(const dtEntity::Message& msg);
|
||||
|
||||
bool ClampToTerrain(osg::Vec3d& position, int voffset = 10000, unsigned int nodemask = dtEntity::NodeMasks::TERRAIN);
|
||||
|
||||
void SetIntersectLayer(dtEntity::StringId);
|
||||
dtEntity::StringId GetIntersectLayer() const;
|
||||
|
||||
|
||||
virtual bool StorePropertiesToScene() const { return true; }
|
||||
|
||||
void SetEnabled(bool v);
|
||||
bool GetEnabled() const;
|
||||
private:
|
||||
|
||||
dtEntity::Property* ScriptGetTerrainHeight(const dtEntity::PropertyArgs& args);
|
||||
|
||||
dtEntityOSG::TransformComponent* GetTransformComp(dtEntity::EntityId eid, GroundClampingComponent* component);
|
||||
void DirtyAll();
|
||||
void HandleIntersection(GroundClampingComponent* component,
|
||||
const osgUtil::LineSegmentIntersector::Intersection& intersection, float dt, double simTime);
|
||||
|
||||
dtEntity::MessageFunctor mTickFunctor;
|
||||
dtEntity::MessageFunctor mCameraAddedFunctor;
|
||||
dtEntity::MessageFunctor mCameraRemovedFunctor;
|
||||
dtEntity::MessageFunctor mMapLoadedFunctor;
|
||||
osgUtil::IntersectionVisitor mIntersectionVisitor;
|
||||
osg::observer_ptr<osg::Node> mRootNode;
|
||||
osg::ref_ptr<osgUtil::IntersectorGroup> mIntersectorGroup;
|
||||
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
dtEntity::DynamicStringIdProperty mIntersectLayer;
|
||||
dtEntity::StringId mIntersectLayerVal;
|
||||
dtEntity::BoolProperty mFetchLODs;
|
||||
|
||||
osgSim::LineOfSight mLos;
|
||||
dtEntityOSG::CameraComponent* mCamera;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Group;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
/**
|
||||
* Holds a single OSG group.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT GroupComponent : public NodeComponent
|
||||
{
|
||||
public:
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId ChildrenId;
|
||||
|
||||
/**
|
||||
* CTor, creates a new group component
|
||||
*/
|
||||
GroupComponent();
|
||||
|
||||
/**
|
||||
* CTor, uses passed group component
|
||||
*/
|
||||
GroupComponent(osg::Group* group);
|
||||
|
||||
virtual ~GroupComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
virtual osg::Group* GetGroup() const;
|
||||
|
||||
// return group to attach children to
|
||||
virtual osg::Group* GetAttachmentGroup() const { return GetGroup(); }
|
||||
|
||||
bool AddChildComponent(dtEntity::ComponentType c);
|
||||
bool RemoveChildComponent(dtEntity::ComponentType c);
|
||||
|
||||
/**
|
||||
* Expects an array of stringid properties containing component types
|
||||
* of children. These will be attached.
|
||||
*/
|
||||
void SetChildren(const dtEntity::PropertyArray& arr);
|
||||
dtEntity::PropertyArray GetChildren() const { return mChildrenVal.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
// to prevent redundant code in constructors
|
||||
void Init();
|
||||
|
||||
dtEntity::DynamicArrayProperty mChildren;
|
||||
dtEntity::ArrayProperty mChildrenVal;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT GroupSystem
|
||||
: public dtEntity::DefaultEntitySystem<GroupComponent>
|
||||
{
|
||||
public:
|
||||
GroupSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::DefaultEntitySystem<GroupComponent>(em, NodeComponent::TYPE)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/logmanager.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Group;
|
||||
}
|
||||
|
||||
namespace osgViewer
|
||||
{
|
||||
class ViewerBase;
|
||||
}
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class EntityManager;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
/**
|
||||
* Convenience setup function for dtEntity.
|
||||
* If you want to do fancy stuff in your setup then maybe you should not call this, instead write your own!
|
||||
*
|
||||
* Installs a log handler, calls SetupDataPaths(), calls InitDtEntity(), calls SetupViewer(), then calls DoScreenSetup()
|
||||
* @param argc number of command line args
|
||||
* @param standard c command line args
|
||||
* @param viewer An instance of either osgViewer::Viewer or osgViewer::CompositeViewer
|
||||
* @param em a valid entity manager
|
||||
* @param addStatsHandler Should osg stats handler be installed (activated with key insert)
|
||||
* @param checkPaths Should SetupDataPaths complain about missing paths
|
||||
* @param addConsoleLog Should log messages be output to console
|
||||
* @param pSceneNode An osg group that is used as scene graph root node. This is added as scene node to the main scene, also
|
||||
* the main update callback that drives dtEntity is installed to this node. If this is NULL, a new osg::Group is created
|
||||
*/
|
||||
bool DTENTITY_OSG_EXPORT InitOSGViewer(int argc, char** argv,
|
||||
osgViewer::ViewerBase& viewer, dtEntity::EntityManager& em,
|
||||
bool addStatsHandler = true, bool checkPaths = true, bool addConsoleLog = true, osg::Group* pSceneNode = 0);
|
||||
|
||||
|
||||
/**
|
||||
* Sets scene graph root node and adds callbacks
|
||||
* @param viewer An instance of either osgViewer::Viewer or osgViewer::CompositeViewer
|
||||
* @param pSceneNode An osg group that is used as scene graph root node. This is added as scene node to the main scene, also
|
||||
* the main update callback that drives dtEntity is installed to this node.
|
||||
*/
|
||||
void DTENTITY_OSG_EXPORT SetupSceneGraph(osgViewer::ViewerBase& viewer, dtEntity::EntityManager& em, osg::Group* pSceneNode);
|
||||
|
||||
|
||||
/**
|
||||
* analyze command line and open OSG window with correct traits
|
||||
* @return true if success
|
||||
*/
|
||||
bool DTENTITY_OSG_EXPORT DoScreenSetup(int argc, char** argv, osgViewer::ViewerBase& viewer, dtEntity::EntityManager& em);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osg/Group>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT LayerAttachPointComponent
|
||||
: public GroupComponent
|
||||
{
|
||||
typedef GroupComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId NameId;
|
||||
|
||||
LayerAttachPointComponent();
|
||||
virtual ~LayerAttachPointComponent();
|
||||
virtual void Finished();
|
||||
void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
void OnRemovedFromEntity(dtEntity::Entity& entity);
|
||||
|
||||
/**
|
||||
* Set osg group node that will hold layer component nodes
|
||||
* as children. When this is set, all layer components are
|
||||
* traversed and their nodes are attached to this group node
|
||||
* if the layer name fits
|
||||
*/
|
||||
virtual void SetNode(osg::Group* node);
|
||||
|
||||
|
||||
/**
|
||||
* Get name SID identifying this layer attach point
|
||||
*/
|
||||
dtEntity::StringId GetName() const { return mName.Get(); }
|
||||
|
||||
/**
|
||||
* Set name SID identifying this layer attach point.
|
||||
* When the name is changed all layer components are
|
||||
* traversed and their nodes are attached to this group node
|
||||
* if the layer name fits
|
||||
*/
|
||||
void SetName(dtEntity::StringId name);
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
private:
|
||||
dtEntity::EntityManager* mEntityManager;
|
||||
dtEntity::StringIdProperty mName;
|
||||
dtEntity::StringId mCurrentName;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT LayerAttachPointSystem
|
||||
: public dtEntity::DefaultEntitySystem<LayerAttachPointComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
friend class LayerAttachPointComponent;
|
||||
|
||||
typedef dtEntity::DefaultEntitySystem<LayerAttachPointComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId DefaultLayerId;
|
||||
static const dtEntity::StringId RootId;
|
||||
|
||||
LayerAttachPointSystem(dtEntity::EntityManager& em);
|
||||
|
||||
virtual bool DeleteComponent(dtEntity::EntityId eid);
|
||||
|
||||
bool GetByName(dtEntity::StringId name, LayerAttachPointComponent*& recipient);
|
||||
|
||||
LayerAttachPointComponent* GetDefaultLayer();
|
||||
LayerAttachPointComponent* GetRootLayer();
|
||||
|
||||
osg::Group* GetSceneGraphRoot()
|
||||
{
|
||||
return mSceneGraphRoot.get();
|
||||
}
|
||||
|
||||
void CreateSceneGraphRootEntity(osg::Group* root);
|
||||
|
||||
dtEntity::Property* ScriptGetByName(const dtEntity::PropertyArgs& args);
|
||||
|
||||
private:
|
||||
|
||||
void RegisterByName(dtEntity::StringId, LayerAttachPointComponent*);
|
||||
typedef std::map<dtEntity::StringId, LayerAttachPointComponent*> LayerByNameMap;
|
||||
LayerByNameMap mLayerByNameMap;
|
||||
osg::ref_ptr<osg::Group> mSceneGraphRoot;
|
||||
dtEntity::EntityId mBaseEntityId;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class LayerAttachPointComponent;
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct EntityData : public osg::Referenced
|
||||
{
|
||||
dtEntity::Entity* mEntity;
|
||||
EntityData(dtEntity::Entity* e)
|
||||
: mEntity(e)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Each visible entity has to have a layer component. The layer component
|
||||
* defines which node component of the entity is attached to which layer.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT LayerComponent
|
||||
: public dtEntity::Component
|
||||
{
|
||||
|
||||
friend class LayerSystem;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId LayerId;
|
||||
static const dtEntity::StringId AttachedComponentId;
|
||||
static const dtEntity::StringId VisibleId;
|
||||
|
||||
LayerComponent();
|
||||
virtual ~LayerComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* The attached component is the component that should be attached
|
||||
* to the layer. A component with this type has to be present on
|
||||
* the entity and it has to derive from NodeComponent.
|
||||
*/
|
||||
void SetAttachedComponent(dtEntity::ComponentType ctype);
|
||||
dtEntity::ComponentType GetAttachedComponent() const;
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity &entity);
|
||||
|
||||
void OnAddedToScene();
|
||||
void OnRemovedFromScene();
|
||||
|
||||
/**
|
||||
* Attach the entity to the layer with this name. Default value is DefaultLayerId
|
||||
*/
|
||||
dtEntity::StringId GetLayer() const;
|
||||
void SetLayer(dtEntity::StringId);
|
||||
|
||||
/**
|
||||
* Is the AttachedComponent currently attached to the layer node?
|
||||
*/
|
||||
bool IsVisible() const;
|
||||
|
||||
/**
|
||||
* Set to false to detach AttachedComponent from the layer node.
|
||||
* Re-attach by setting to true.
|
||||
*/
|
||||
void SetVisible(bool);
|
||||
|
||||
/**
|
||||
* Is the entity already added to scene? Can be used to query current initialization status
|
||||
*/
|
||||
bool IsAddedToScene() const { return mAddedToScene; }
|
||||
|
||||
/**
|
||||
* Get OSG node of attached component
|
||||
*/
|
||||
osg::Node* GetAttachedComponentNode() const;
|
||||
|
||||
/**
|
||||
* @return bool if geometry is attached to layer component
|
||||
*/
|
||||
bool GetBoundingBox(dtEntity::Vec3d& min, dtEntity::Vec3d& max);
|
||||
|
||||
/**
|
||||
* Add attached component node to layer as a child in the scene graph hierarchy
|
||||
*/
|
||||
bool Attach(LayerAttachPointComponent* current);
|
||||
|
||||
/**
|
||||
* Add attached component node to layer as a child in the scene graph hierarchy
|
||||
*/
|
||||
bool Detach(LayerAttachPointComponent* current);
|
||||
|
||||
private:
|
||||
|
||||
// is there an attach point, a component to attach and added to scene?
|
||||
bool CanAttach();
|
||||
dtEntity::Entity* mEntity;
|
||||
dtEntity::DynamicBoolProperty mVisible;
|
||||
bool mVisibleVal;
|
||||
dtEntity::DynamicStringIdProperty mLayer;
|
||||
dtEntity::StringId mLayerVal;
|
||||
dtEntity::DynamicStringIdProperty mAttachedComponent;
|
||||
dtEntity::StringId mAttachedComponentVal;
|
||||
bool mAddedToScene;
|
||||
|
||||
};
|
||||
|
||||
LayerAttachPointComponent* GetAttachPoint(dtEntity::EntityManager& em, dtEntity::StringId name);
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT LayerSystem
|
||||
: public dtEntity::DefaultEntitySystem<LayerComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
static const dtEntity::StringId VisibilityBitsId;
|
||||
|
||||
LayerSystem(dtEntity::EntityManager& em);
|
||||
~LayerSystem();
|
||||
|
||||
void OnEnterWorld(const dtEntity::Message&);
|
||||
void OnLeaveWorld(const dtEntity::Message&);
|
||||
|
||||
void AddVisibleBoundingBox(dtEntity::EntityId id);
|
||||
void RemoveVisibleBoundingBox(dtEntity::EntityId id);
|
||||
void RemoveAllBoundingBoxes();
|
||||
|
||||
// set or clear these bits when visibility of component is toggled
|
||||
void SetVisibilityBits(unsigned int bits) { mVisibilityBits.Set(bits); }
|
||||
unsigned int GetVisibilityBits() const { return mVisibilityBits.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::Property* ScriptAddVisibleBoundingBox(const dtEntity::PropertyArgs& args)
|
||||
{
|
||||
AddVisibleBoundingBox(args[0]->UIntValue());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dtEntity::Property* ScriptRemoveVisibleBoundingBox(const dtEntity::PropertyArgs& args)
|
||||
{
|
||||
RemoveVisibleBoundingBox(args[0]->UIntValue());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dtEntity::Property* ScriptRemoveAllBoundingBoxes(const dtEntity::PropertyArgs& args)
|
||||
{
|
||||
RemoveAllBoundingBoxes();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dtEntity::Property* ScriptGetBoundingSphere(const dtEntity::PropertyArgs& args);
|
||||
|
||||
dtEntity::MessageFunctor mEnterWorldFunctor;
|
||||
dtEntity::MessageFunctor mLeaveWorldFunctor;
|
||||
|
||||
dtEntity::UIntProperty mVisibilityBits;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/entity.h>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Light;
|
||||
class LightSource;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT LightComponent : public NodeComponent
|
||||
{
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
static const dtEntity::StringId LightNumId;
|
||||
static const dtEntity::StringId PositionId;
|
||||
static const dtEntity::StringId AmbientId;
|
||||
static const dtEntity::StringId DiffuseId;
|
||||
static const dtEntity::StringId SpecularId;
|
||||
static const dtEntity::StringId SpotCutoffId;
|
||||
static const dtEntity::StringId SpotExponentId;
|
||||
static const dtEntity::StringId DirectionId;
|
||||
static const dtEntity::StringId ConstantAttenuationId;
|
||||
static const dtEntity::StringId LinearAttenuationId;
|
||||
static const dtEntity::StringId QuadraticAttenuationId;
|
||||
|
||||
LightComponent();
|
||||
virtual ~LightComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
osg::Light* GetLight() { return mLight; }
|
||||
|
||||
private:
|
||||
|
||||
osg::Vec4 GetLightPosition() const;
|
||||
osg::Vec4 GetAmbient() const;
|
||||
osg::Vec4 GetDiffuse() const;
|
||||
osg::Vec4 GetSpecular() const;
|
||||
osg::Vec3 GetDirection() const;
|
||||
|
||||
osg::Light* mLight;
|
||||
dtEntity::DynamicIntProperty mLightNum;
|
||||
dtEntity::DynamicVec4Property mAmbient;
|
||||
dtEntity::DynamicVec4Property mDiffuse;
|
||||
dtEntity::DynamicVec4Property mSpecular;
|
||||
dtEntity::DynamicVec4Property mPosition;
|
||||
dtEntity::DynamicVec3Property mDirection;
|
||||
dtEntity::DynamicFloatProperty mConstantAttenuation;
|
||||
dtEntity::DynamicFloatProperty mLinearAttenuation;
|
||||
dtEntity::DynamicFloatProperty mQuadraticAttenuation;
|
||||
dtEntity::DynamicFloatProperty mSpotExponent;
|
||||
dtEntity:: DynamicFloatProperty mSpotCutOff;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT LightSystem
|
||||
: public dtEntity::DefaultEntitySystem<LightComponent>
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<LightComponent> BaseClass;
|
||||
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
LightSystem(dtEntity::EntityManager& em);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <osgManipulator/Dragger>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class ManipulatorComponent
|
||||
: public dtEntityOSG::NodeComponent
|
||||
{
|
||||
|
||||
typedef dtEntityOSG::NodeComponent BaseClass;
|
||||
|
||||
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId LayerId;
|
||||
static const dtEntity::StringId DraggerTypeId;
|
||||
static const dtEntity::StringId OffsetFromStartId;
|
||||
static const dtEntity::StringId KeepSizeConstantId;
|
||||
static const dtEntity::StringId UseLocalCoordsId;
|
||||
static const dtEntity::StringId PivotAtBottomId;
|
||||
|
||||
static const dtEntity::StringId TabPlaneDraggerId;
|
||||
static const dtEntity::StringId TabPlaneTrackballDraggerId;
|
||||
static const dtEntity::StringId TabBoxTrackballDraggerId;
|
||||
static const dtEntity::StringId TrackballDraggerId;
|
||||
static const dtEntity::StringId Translate1DDraggerId;
|
||||
static const dtEntity::StringId Translate2DDraggerId;
|
||||
static const dtEntity::StringId TranslateAxisDraggerId;
|
||||
static const dtEntity::StringId TabBoxDraggerId;
|
||||
static const dtEntity::StringId TerrainTranslateDraggerId;
|
||||
static const dtEntity::StringId ScaleDraggerId;
|
||||
|
||||
|
||||
ManipulatorComponent();
|
||||
virtual ~ManipulatorComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& e);
|
||||
virtual void OnRemovedFromEntity(dtEntity::Entity& e);
|
||||
virtual void Finished();
|
||||
|
||||
osgManipulator::Dragger* GetDragger() const;
|
||||
|
||||
/**
|
||||
* Attach the dragger to the layer with this name. Default value is DefaultLayerId
|
||||
*/
|
||||
dtEntity::StringId GetLayer() const;
|
||||
void SetLayer(dtEntity::StringId);
|
||||
|
||||
dtEntity::StringId GetDraggerType() const { return mDraggerTypeVal; }
|
||||
void SetDraggerType(dtEntity::StringId);
|
||||
|
||||
void SetOffsetFromStart(const osg::Vec3d& v);
|
||||
osg::Vec3d GetOffsetFromStart() const { return mOffsetFromStartVal; }
|
||||
|
||||
void SetUseLocalCoords(bool v);
|
||||
bool GetUseLocalCoords() const { return mUseLocalCoordsVal; }
|
||||
|
||||
void SetKeepSizeConstant(bool v);
|
||||
bool GetKeepSizeConstant() const { return mKeepSizeConstantVal; }
|
||||
|
||||
void SetPivotAtBottom(bool v);
|
||||
bool GetPivotAtBottom() const { return mPivotAtBottomVal; }
|
||||
|
||||
private:
|
||||
|
||||
void RemoveFromParent();
|
||||
void AddToLayer();
|
||||
|
||||
osg::ref_ptr<osgManipulator::DraggerCallback> mDraggerCallback;
|
||||
dtEntity::DynamicStringIdProperty mLayerProperty;
|
||||
dtEntity::StringId mLayerVal;
|
||||
dtEntity::StringId mAttachPoint;
|
||||
dtEntity::DynamicStringIdProperty mDraggerType;
|
||||
dtEntity::StringId mDraggerTypeVal;
|
||||
dtEntity::DynamicVec3dProperty mOffsetFromStart;
|
||||
osg::Vec3 mOffsetFromStartVal;
|
||||
dtEntity::DynamicBoolProperty mKeepSizeConstant;
|
||||
bool mKeepSizeConstantVal;
|
||||
dtEntity::DynamicBoolProperty mUseLocalCoords;
|
||||
bool mUseLocalCoordsVal;
|
||||
dtEntity::DynamicBoolProperty mPivotAtBottom;
|
||||
bool mPivotAtBottomVal;
|
||||
osg::ref_ptr<osg::Group> mDraggerContainer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ManipulatorSystem
|
||||
: public dtEntity::DefaultEntitySystem<ManipulatorComponent>
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<ManipulatorComponent> BaseClass;
|
||||
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId UseLocalCoordsId;
|
||||
static const dtEntity::StringId UseGroundClampingId;
|
||||
|
||||
ManipulatorSystem(dtEntity::EntityManager& em);
|
||||
~ManipulatorSystem();
|
||||
|
||||
// don't store manipulators to map
|
||||
virtual bool StoreComponentsToMap() const { return false; }
|
||||
|
||||
// don't copy manipulators with entities, also don't store to spawners
|
||||
virtual bool AllowComponentCreationBySpawner() const { return false; }
|
||||
|
||||
void SetUseLocalCoords(bool v);
|
||||
bool GetUseLocalCoords() const { return mUseLocalCoordsVal; }
|
||||
|
||||
void SetUseGroundClamping(bool v) { mUseGroundClamping.Set(v); }
|
||||
bool GetUseGroundClamping() const { return mUseGroundClamping.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicBoolProperty mUseLocalCoords;
|
||||
bool mUseLocalCoordsVal;
|
||||
dtEntity::BoolProperty mUseGroundClamping;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osgManipulator/Dragger>
|
||||
#include <osgManipulator/TabBoxDragger>
|
||||
#include <osgManipulator/TabBoxTrackballDragger>
|
||||
#include <osgManipulator/TabPlaneDragger>
|
||||
#include <osgManipulator/TabPlaneTrackballDragger>
|
||||
#include <osgManipulator/TrackballDragger>
|
||||
#include <osgManipulator/Translate1DDragger>
|
||||
#include <osgManipulator/Translate2DDragger>
|
||||
#include <osgManipulator/TranslateAxisDragger>
|
||||
#include <osgManipulator/Scale1DDragger>
|
||||
#include <osgManipulator/ScaleAxisDragger>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class TerrainTranslateDragger : public osgManipulator::CompositeDragger
|
||||
{
|
||||
typedef osgManipulator::CompositeDragger BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
TerrainTranslateDragger();
|
||||
virtual void setupDefaultGeometry();
|
||||
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osgManipulator::Translate1DDragger> _xDragger;
|
||||
osg::ref_ptr<osgManipulator::Translate1DDragger> _yDragger;
|
||||
osg::ref_ptr<osgManipulator::Translate1DDragger> _zDragger;
|
||||
osg::ref_ptr<osgManipulator::Translate2DDragger > _translate2DDragger;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class ScaleAllDragger : public osgManipulator::Dragger
|
||||
{
|
||||
public:
|
||||
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
|
||||
|
||||
protected:
|
||||
osg::Vec2 _startPoint;
|
||||
osg::Matrix _localToWorld;
|
||||
osg::Matrix _worldToLocal;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class ScaleDragger : public osgManipulator::CompositeDragger
|
||||
{
|
||||
typedef osgManipulator::CompositeDragger BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
ScaleDragger();
|
||||
virtual void setupDefaultGeometry();
|
||||
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
private:
|
||||
void setupGeometry(osgManipulator::Scale1DDragger*, const osg::Vec4& color);
|
||||
osg::ref_ptr<osgManipulator::Scale1DDragger> _xDragger;
|
||||
osg::ref_ptr<osgManipulator::Scale1DDragger> _yDragger;
|
||||
osg::ref_ptr<osgManipulator::Scale1DDragger> _zDragger;
|
||||
osg::ref_ptr<ScaleAllDragger> _scaleAllDragger;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class TrackballDragger : public osgManipulator::TrackballDragger
|
||||
{
|
||||
typedef osgManipulator::TrackballDragger BaseClass;
|
||||
public:
|
||||
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/transformcomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class MatrixTransform;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* holds a single matrix transform
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT MatrixTransformComponent
|
||||
: public TransformComponent
|
||||
{
|
||||
typedef TransformComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId MatrixId;
|
||||
|
||||
MatrixTransformComponent();
|
||||
MatrixTransformComponent(osg::MatrixTransform* trans);
|
||||
|
||||
virtual ~MatrixTransformComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
const osg::MatrixTransform* GetMatrixTransform() const;
|
||||
osg::MatrixTransform* GetMatrixTransform();
|
||||
|
||||
virtual dtEntity::Matrix GetMatrix() const;
|
||||
virtual void SetMatrix(const dtEntity::Matrix& m);
|
||||
|
||||
virtual dtEntity::Vec3d GetTranslation() const
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
return m.getTrans();
|
||||
}
|
||||
|
||||
virtual void SetTranslation(const dtEntity::Vec3d& t)
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
m.setTrans(t);
|
||||
SetMatrix(m);
|
||||
}
|
||||
|
||||
virtual dtEntity::Quat GetRotation() const
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
return m.getRotate();
|
||||
}
|
||||
|
||||
virtual void SetRotation(const dtEntity::Quat& q)
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
m.setRotate(q);
|
||||
SetMatrix(m);
|
||||
}
|
||||
|
||||
virtual dtEntity::Vec3d GetScale() const
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
return m.getScale();
|
||||
}
|
||||
|
||||
virtual void SetScale(const dtEntity::Vec3d& v)
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
m = m.scale(v);
|
||||
SetMatrix(m);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicMatrixProperty mMatrix;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT MatrixTransformSystem
|
||||
: public dtEntity::DefaultEntitySystem<MatrixTransformComponent>
|
||||
{
|
||||
public:
|
||||
MatrixTransformSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::DefaultEntitySystem<MatrixTransformComponent>(em, TransformComponent::TYPE)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osg/Node>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT NodeStore
|
||||
{
|
||||
public:
|
||||
|
||||
NodeStore();
|
||||
NodeStore(osg::Node* node);
|
||||
virtual ~NodeStore();
|
||||
|
||||
/**
|
||||
* returns encapsulated node
|
||||
*/
|
||||
virtual osg::Node* GetNode() const;
|
||||
|
||||
/**
|
||||
* Sets encapsulated node. Also, if the currently held node
|
||||
* is attached as a child to another component then it is
|
||||
* removed from that parent and the passed node is added as a child
|
||||
*/
|
||||
virtual void SetNode(osg::Node* node);
|
||||
|
||||
/**
|
||||
* type of compponent that this node component is attached to.
|
||||
* Is 0 if not attached to a parent
|
||||
*/
|
||||
dtEntity::ComponentType GetParentComponent() const { return mParentComponent; }
|
||||
void SetParentComponent(dtEntity::ComponentType c) { mParentComponent = c; }
|
||||
|
||||
void ClearFromParent();
|
||||
|
||||
void SetNodeMask(unsigned int nodemask, bool recursive = false);
|
||||
unsigned int GetNodeMask() const;
|
||||
|
||||
void SetNodeEntity(dtEntity::Entity*);
|
||||
dtEntity::Entity* GetNodeEntity();
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Node> mNode;
|
||||
dtEntity::ComponentType mParentComponent;
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Holds a single OSG node. Subclass this if you want to wrap an object
|
||||
* derived from osg::Node. NodeComponent instances can be attached to
|
||||
* the scene by the Layer system.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT NodeComponent
|
||||
: public dtEntity::Component
|
||||
, public NodeStore
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
NodeComponent();
|
||||
NodeComponent(osg::Node* node);
|
||||
virtual ~NodeComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
virtual void OnRemovedFromEntity(dtEntity::Entity& entity);
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT NodeSystem
|
||||
: public dtEntity::DefaultEntitySystem<NodeComponent>
|
||||
{
|
||||
public:
|
||||
NodeSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::DefaultEntitySystem<NodeComponent>(em)
|
||||
{
|
||||
|
||||
}
|
||||
};}
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
|
||||
#include <osg/Group>
|
||||
#include <osg/NodeVisitor>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
class NodeMaskVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
NodeMaskVisitor(unsigned int mask) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
|
||||
{
|
||||
mMask = mask;
|
||||
}
|
||||
|
||||
virtual void apply(osg::Group& node)
|
||||
{
|
||||
node.setNodeMask(mMask);
|
||||
this->traverse(node);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
unsigned int mMask;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class DTENTITY_OSG_EXPORT OSGAnimationComponent : public dtEntity::Component
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
|
||||
OSGAnimationComponent();
|
||||
virtual ~OSGAnimationComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
|
||||
osgAnimation::BasicAnimationManager* GetAnimationManager() const
|
||||
{
|
||||
return mAnimationManager;
|
||||
}
|
||||
|
||||
void SetupMesh(osg::Node*);
|
||||
|
||||
void SetEnabled(bool);
|
||||
bool GetEnabled() const;
|
||||
|
||||
bool AddAttachment(const std::string& boneName, osg::Node* node, const osg::Matrix& m);
|
||||
bool RemoveAtachment(const std::string& boneName, osg::Node* node);
|
||||
void RemoveAtachments(const std::string& boneName);
|
||||
|
||||
private:
|
||||
|
||||
osg::ref_ptr<osgAnimation::BasicAnimationManager> mAnimationManager;
|
||||
dtEntity::Entity* mEntity;
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT OSGAnimationSystem
|
||||
: public dtEntity::DefaultEntitySystem<OSGAnimationComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId VertexShaderId;
|
||||
static const dtEntity::StringId FragmentShaderId;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
|
||||
OSGAnimationSystem(dtEntity::EntityManager& em);
|
||||
~OSGAnimationSystem();
|
||||
|
||||
void OnMeshChanged(const dtEntity::Message&);
|
||||
|
||||
void SetVertexShader(const std::string& v) { mVertexShader.Set(v); }
|
||||
std::string GetVertexShader() const { return mVertexShader.Get(); }
|
||||
|
||||
void SetFragmentShader(const std::string& v) { mFragmentShader.Set(v); }
|
||||
std::string GetFragmentShader() const { return mFragmentShader.Get(); }
|
||||
|
||||
void SetEnabled(bool);
|
||||
bool GetEnabled() const;
|
||||
|
||||
private:
|
||||
|
||||
bool GetAnimationList(dtEntity::EntityId id, const osgAnimation::AnimationList*& list,
|
||||
osgAnimation::BasicAnimationManager*& manager);
|
||||
dtEntity::Property* ScriptPlayAnimation(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptStopAnimation(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptGetAnimations(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptGetAnimationLength(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptGetAnimationPlayMode(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetAnimationPlayMode(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptAddAttachment(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptRemoveAttachments(const dtEntity::PropertyArgs& args);
|
||||
|
||||
dtEntity::MessageFunctor mMeshChangedFunctor;
|
||||
dtEntity::StringProperty mVertexShader;
|
||||
dtEntity::StringProperty mFragmentShader;
|
||||
bool mEnabledVal;
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/core.h>
|
||||
#include <dtEntity/debugdrawinterface.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/entitymanager.h>
|
||||
#include <dtEntityOSG/layerattachpointcomponent.h>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Group>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Geode;
|
||||
class Geometry;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Can be used to add simple debug geometry to the scene. Each debug graphics primitive is added
|
||||
* together with a lifetime / duration.
|
||||
* If you want to do per-frame drawing, simply set a duration of 0 and
|
||||
* execute the draw each frame.
|
||||
* Warning: To use, first do SetEnabled(true), it is off by default!
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT OSGDebugDrawInterface
|
||||
: public dtEntity::DebugDrawInterface
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param layer Add debug draw manager to layer of this name
|
||||
*/
|
||||
OSGDebugDrawInterface(dtEntity::EntityManager& em,
|
||||
dtEntity::StringId layer = dtEntity::StringId());
|
||||
~OSGDebugDrawInterface();
|
||||
|
||||
/**
|
||||
* message functors, don't call directly
|
||||
*/
|
||||
void Tick(const dtEntity::Message& msg);
|
||||
void OnEnable(const dtEntity::Message& m);
|
||||
|
||||
/**
|
||||
* Draw a single point
|
||||
* @param position Draw point here
|
||||
* @param color Draw with this color
|
||||
* @param size Size of points in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddPoint(const dtEntity::Vec3f& position, const dtEntity::Vec4f& color,
|
||||
int size = 1, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw multiple points
|
||||
* @param positions A vector of point positions
|
||||
* @param color Draw with this color
|
||||
* @param size Size of points in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddPoints(const std::vector<dtEntity::Vec3f>& positions, const dtEntity::Vec4f& color,
|
||||
int size = 1, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a single line
|
||||
* @param start Line starts here
|
||||
* @param end Line ends here
|
||||
* @param color Draw with this color
|
||||
* @param linewidth Width of line in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddLine(const dtEntity::Vec3f& start, const dtEntity::Vec3f& end,
|
||||
const dtEntity::Vec4f& color, int linewidth = 1, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a number of lines
|
||||
* @param lines A vector containing two entries for each line. So to draw two lines you have to have four entries.
|
||||
* @param color Draw with this color
|
||||
* @param linewidth Width of line in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddLines(const std::vector<dtEntity::Vec3f>& lines, const dtEntity::Vec4f& color,
|
||||
int linewidth = 1, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a 3d cross
|
||||
* @param position Draw point here
|
||||
* @param color Draw with this color
|
||||
* @param size length of each arm
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddCross(const dtEntity::Vec3f& position, const dtEntity::Vec4f& color, float size,
|
||||
float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a sphere
|
||||
* @param position Draw sphere here
|
||||
* @param radius radius of sphere
|
||||
* @param color Draw with this color
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddSphere(const dtEntity::Vec3f& position, float radius, const dtEntity::Vec4f& color,
|
||||
float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a single triangle
|
||||
* @param vert0 First vertex of triangle
|
||||
* @param vert1 Second vertex of triangle
|
||||
* @param vert2 Third vertex of triangle
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddTriangle(const dtEntity::Vec3f& vert0, const dtEntity::Vec3f& vert1,
|
||||
const dtEntity::Vec3f& vert2, const dtEntity::Vec4f& color,
|
||||
int lineWidth, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw multiple triangles
|
||||
* @param verts A vector containing triangle verts. The vector should contain three entries for each triangle.
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddTriangles(const std::vector<dtEntity::Vec3f>& verts, const dtEntity::Vec4f& color,
|
||||
int lineWidth, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a mesh
|
||||
* @param geometry The OSG geometry that should be drawn
|
||||
* @param position Draw geometry here
|
||||
* @param lineColor Draw wireframe with this color. If alpha value is 0 then wireframe will not be drawn
|
||||
* @param lineWidth Draw wireframe with this line with. If value is 0 then wireframe will not be drawn
|
||||
* @param faceColor Draw polygons with this color. Blending is enabled, so feel free to set an alpha value.
|
||||
* Alpha value 0 means no polygons are drawn
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddMesh(osg::Geometry* geometry, const dtEntity::Vec3f& position,
|
||||
const dtEntity::Vec4f& lineColor, int lineWidth,
|
||||
const dtEntity::Vec4f& faceColor, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a circle
|
||||
* @param position Center of circle is here
|
||||
* @param planeNormal A normal vector pointing away from the face of the disk
|
||||
* @param radius Radius of disk
|
||||
* @param color Draw with this color
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddCircle(const dtEntity::Vec3f& position, const dtEntity::Vec3f& planeNormal,
|
||||
float radius, const dtEntity::Vec4f& color, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a text string
|
||||
* @param position Draw text here
|
||||
* @param str The text to draw
|
||||
* @param color Draw with this color
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddString(const dtEntity::Vec3f& position, const std::string& str,
|
||||
const dtEntity::Vec4f& color, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw an axis aligned bounding box
|
||||
* @param minCoords start box from here
|
||||
* @param maxCoords end box here
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddAABB(const dtEntity::Vec3f& minCoords, const dtEntity::Vec3f& maxCoords,
|
||||
const dtEntity::Vec4f& color, int lineWidth, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Add an oriented bounding box
|
||||
* @param matrix transformation matrix to apply to box
|
||||
* @param minCoords start box from here
|
||||
* @param maxCoords end box here
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddOBB(const dtEntity::Matrix& matrix, const dtEntity::Vec3f& minCoords,
|
||||
const dtEntity::Vec3f& maxCoords, const dtEntity::Vec4f& color,
|
||||
int lineWidth, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Add a cross showing coordinate orientation
|
||||
* @param matrix transformation cross by this matrix
|
||||
* @param color Draw with this color
|
||||
* @param size length of cross arms
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddAxes(const dtEntity::Matrix& matrix, const dtEntity::Vec4f& color,
|
||||
float size, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Add an OSG drawable
|
||||
* @param drawable Add this drawable
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddDrawable(osg::Drawable* drawable, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* DebugDrawInterface is disabled by default, enable it!
|
||||
*/
|
||||
void SetEnabled(bool enabled);
|
||||
bool IsEnabled() const;
|
||||
|
||||
/**
|
||||
* Immediately remove all debug geometry
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
/**
|
||||
If context id is set then a redraw of that context is requested from OSG.
|
||||
Only relevant when render on demand is used.
|
||||
*/
|
||||
void SetContextId(unsigned int v)
|
||||
{
|
||||
mContextId = v;
|
||||
mContextIdSet = true;
|
||||
}
|
||||
unsigned int GetContextId() const { return mContextId; }
|
||||
|
||||
private:
|
||||
bool mEnabled;
|
||||
|
||||
// osg group with stateset depth test enabled
|
||||
osg::ref_ptr<osg::Group> mGroupDepthTest;
|
||||
|
||||
// osg group with stateset depth test disabled
|
||||
osg::ref_ptr<osg::Group> mGroupNoDepthTest;
|
||||
|
||||
double mCurrentTime;
|
||||
dtEntity::EntityManager* mEntityManager;
|
||||
dtEntity::MessageFunctor mEnableFunctor;
|
||||
dtEntity::MessageFunctor mTickFunctor;
|
||||
dtEntity::StringId mLayerName;
|
||||
int mContextId;
|
||||
bool mContextIdSet;
|
||||
void RequestRedraw();
|
||||
};
|
||||
|
||||
inline OSGDebugDrawInterface* GetOSGDebugDrawInterface()
|
||||
{
|
||||
return static_cast<OSGDebugDrawInterface*>(dtEntity::GetDebugDrawInterface());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/core.h>
|
||||
#include <dtEntity/inputinterface.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <sstream>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class MessagePump;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// for use with GuiEventAdapter user event
|
||||
class MouseEnterLeaveEvent : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
bool mFocused;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class DTENTITY_OSG_EXPORT OSGInputInterface
|
||||
: public dtEntity::InputInterface
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
// can't make OSGInputInterface derive from osgGA::GUIEventHandler because
|
||||
// we don't want to inherit osg::Referenced stuff
|
||||
class EventHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
OSGInputInterface* mIface;
|
||||
public:
|
||||
EventHandler(OSGInputInterface* i)
|
||||
: mIface(i)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* o, osg::NodeVisitor* nv)
|
||||
{
|
||||
return mIface->handle(ea, aa, o, nv);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
osgGA::GUIEventHandler* GetEventHandler() { return mEventHandler; }
|
||||
|
||||
typedef std::map<std::string, osgGA::GUIEventAdapter::KeySymbol> KeyNames;
|
||||
typedef std::map<int, std::string> KeyNamesReverse;
|
||||
|
||||
OSGInputInterface(dtEntity::MessagePump&);
|
||||
virtual ~OSGInputInterface();
|
||||
|
||||
//virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*);
|
||||
|
||||
virtual void AddInputCallback(dtEntity::InputCallbackInterface*);
|
||||
virtual bool RemoveInputCallback(dtEntity::InputCallbackInterface*);
|
||||
|
||||
/**
|
||||
* Stores if current system is multitouch-capable
|
||||
*/
|
||||
virtual bool GetMultiTouchEnabled() const { return mMultiTouchEnabled; }
|
||||
virtual void SetMultiTouchEnabled(bool v) { mMultiTouchEnabled = v; }
|
||||
|
||||
virtual bool GetLockCursor() const { return mLockCursor; }
|
||||
virtual void SetLockCursor(bool v) { mLockCursor = v; }
|
||||
|
||||
/**
|
||||
* Multitouch interface: return number of touch points
|
||||
*/
|
||||
virtual size_t GetNumTouches() const { return mNumTouches; }
|
||||
|
||||
/**
|
||||
* Multitouch interface: return touch points
|
||||
*/
|
||||
virtual std::vector<dtEntity::TouchPoint> GetTouches() const { return mTouches; }
|
||||
|
||||
/**
|
||||
* Return true if key is pressed, else false
|
||||
*/
|
||||
bool GetKey(const std::string& name, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return true if key was released this frame, else false
|
||||
*/
|
||||
virtual bool GetKeyUp(const std::string& name, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return true if key was pressed down this frame, else false
|
||||
*/
|
||||
virtual bool GetKeyDown(const std::string& name, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Returns true if any keyboard key is currently pressed
|
||||
*/
|
||||
virtual bool AnyKeyDown() const;
|
||||
|
||||
/**
|
||||
* Return string entered this frame
|
||||
*/
|
||||
virtual std::string GetInputString() const;
|
||||
|
||||
/**
|
||||
* Return true if given mouse button is currently pressed.
|
||||
* 0 for left button, 1 for right, 2 for center
|
||||
*/
|
||||
virtual bool GetMouseButton(int button, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return true if given mouse button was pressed this frame.
|
||||
* 0 for left button, 1 for right, 2 for center
|
||||
*/
|
||||
virtual bool GetMouseButtonDown(int button, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return true if given mouse button was released this frame.
|
||||
* 0 for left button, 1 for right, 2 for center
|
||||
*/
|
||||
virtual bool GetMouseButtonUp(int button, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return axis value from -1 to 1
|
||||
* @TODO: Axes are currently hard coded
|
||||
*/
|
||||
virtual double GetAxis(dtEntity::StringId axisname) const;
|
||||
|
||||
/**
|
||||
* Return current mouse wheel state. -1 = down, 1 = up, 0 = no motion
|
||||
*/
|
||||
virtual int GetMouseWheelState(unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return a list containing names of all registered keys
|
||||
*/
|
||||
void GetKeyNames(std::map<std::string, unsigned int>&) const;
|
||||
|
||||
/**
|
||||
* Get OSG key symbol from key name
|
||||
*/
|
||||
osgGA::GUIEventAdapter::KeySymbol GetKeySymbol(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Clear stuff at end of frame
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/**
|
||||
* React to OSG input events
|
||||
*/
|
||||
bool handleInternal(const osgGA::GUIEventAdapter& ea);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventHandler> mEventHandler;
|
||||
|
||||
void HandleMultiTouch(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleKeyUp(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleKeyDown(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseUp(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseDown(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseMove(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseWheel(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseEnterLeave(const osgGA::GUIEventAdapter& ea);
|
||||
|
||||
dtEntity::MessagePump* mMessagePump;
|
||||
bool mMultiTouchEnabled;
|
||||
bool mLockCursor;
|
||||
size_t mNumTouches;
|
||||
std::vector<dtEntity::TouchPoint> mTouches;
|
||||
|
||||
typedef std::vector<dtEntity::InputCallbackInterface*> Callbacks;
|
||||
Callbacks mCallbacks;
|
||||
|
||||
// pair of context id, key
|
||||
typedef std::set<std::pair<unsigned int, int> > ContextKeyMap;
|
||||
ContextKeyMap mKeyPressedSet;
|
||||
ContextKeyMap mKeyUpSet;
|
||||
ContextKeyMap mKeyDownSet;
|
||||
|
||||
KeyNames mKeyNames;
|
||||
KeyNamesReverse mKeyNamesReverse;
|
||||
|
||||
typedef std::set<std::pair<unsigned int, int> > ContextButtonMap;
|
||||
ContextButtonMap mMouseButtonPressed;
|
||||
ContextButtonMap mMouseButtonUp;
|
||||
ContextButtonMap mMouseButtonDown;
|
||||
|
||||
float mMouseX;
|
||||
float mMouseY;
|
||||
|
||||
int mMouseXRaw;
|
||||
int mMouseYRaw;
|
||||
int mMouseDeltaXRaw;
|
||||
int mMouseDeltaYRaw;
|
||||
float mMouseDeltaX;
|
||||
float mMouseDeltaY;
|
||||
|
||||
unsigned int mFrameNumber;
|
||||
int mMouseScroll;
|
||||
unsigned int mMouseScrollContext;
|
||||
std::ostringstream mInputString;
|
||||
|
||||
bool mNeedReset; // internal flag to check when to reset
|
||||
};
|
||||
|
||||
inline OSGInputInterface* GetOSGInputInterface()
|
||||
{
|
||||
return static_cast<OSGInputInterface*>(dtEntity::GetInputInterface());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/core.h>
|
||||
#include <dtEntity/systeminterface.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <osgViewer/ViewerBase>
|
||||
#include <vector>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class MessagePump;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT OSGSystemInterface : public dtEntity::SystemInterface
|
||||
{
|
||||
public:
|
||||
|
||||
OSGSystemInterface(dtEntity::MessagePump&, int argc, const char** argv);
|
||||
~OSGSystemInterface();
|
||||
|
||||
void InstallUpdateCallback(osg::Node* node);
|
||||
|
||||
void SetViewer(osgViewer::ViewerBase* v) { mViewer = v; }
|
||||
osgViewer::ViewerBase* GetViewer() const { return mViewer.get(); }
|
||||
|
||||
osgViewer::View* GetPrimaryView() const;
|
||||
osgViewer::GraphicsWindow* GetPrimaryWindow() const;
|
||||
osg::Camera* GetPrimaryCamera() const;
|
||||
|
||||
virtual void EmitTickMessagesAndQueuedMessages();
|
||||
|
||||
virtual void EmitPostUpdateMessage();
|
||||
|
||||
virtual float GetDeltaSimTime() const;
|
||||
virtual float GetDeltaRealTime() const;
|
||||
virtual dtEntity::Timer_t GetRealClockTime();
|
||||
virtual double GetSimulationTime() const;
|
||||
void SetSimulationTime(double);
|
||||
|
||||
virtual float GetTimeScale() const;
|
||||
virtual void SetTimeScale(float v);
|
||||
|
||||
virtual dtEntity::Timer_t GetSimulationClockTime() const;
|
||||
virtual void SetSimulationClockTime(dtEntity::Timer_t t);
|
||||
|
||||
void SetTimeValues(double simulationTime, float deltaSimTime,float deltaTime, dtEntity::Timer_t clockTime);
|
||||
|
||||
/**
|
||||
* Get absolute path from a relative file path.
|
||||
* Returns empty string if file is not found
|
||||
*/
|
||||
virtual std::string FindDataFile(const std::string& filename);
|
||||
|
||||
/**
|
||||
* return true if a file exists
|
||||
*/
|
||||
virtual bool FileExists(const std::string& filename);
|
||||
|
||||
virtual int GetArgC() { return mArgC; }
|
||||
virtual const char** GetArgV() { return mArgV; }
|
||||
|
||||
private:
|
||||
osg::observer_ptr<osgViewer::ViewerBase> mViewer;
|
||||
dtEntity::MessagePump* mMessagePump;
|
||||
class Impl;
|
||||
Impl* mImpl;
|
||||
|
||||
int mArgC;
|
||||
const char** mArgV;
|
||||
|
||||
};
|
||||
|
||||
inline OSGSystemInterface* GetOSGSystemInterface()
|
||||
{
|
||||
return static_cast<OSGSystemInterface*>(dtEntity::GetSystemInterface());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/core.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/messagepump.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/windowinterface.h>
|
||||
#include <osg/GraphicsContext>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class EntityManager;
|
||||
}
|
||||
|
||||
namespace osgViewer
|
||||
{
|
||||
class GraphicsWindow;
|
||||
class View;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT OSGWindowInterface : public dtEntity::WindowInterface
|
||||
{
|
||||
public:
|
||||
|
||||
struct WindowPos
|
||||
{
|
||||
int mX;
|
||||
int mY;
|
||||
int mW;
|
||||
int mH;
|
||||
bool mWindowDeco;
|
||||
};
|
||||
|
||||
OSGWindowInterface(dtEntity::EntityManager& em);
|
||||
~OSGWindowInterface();
|
||||
|
||||
osgViewer::GraphicsWindow* GetWindowByContextId(unsigned int contextId) const;
|
||||
osgViewer::View* GetViewByContextId(unsigned int contextId) const;
|
||||
|
||||
/**
|
||||
* Opens a new window if used viewer is a composite viewer.
|
||||
* @param name Name of osg nodes for window, view and camera to set
|
||||
* @param traits OSG GraphicsWindow traits to use
|
||||
* @contextId receives context id of newly created context
|
||||
* @return true if success, else false
|
||||
*/
|
||||
virtual bool OpenWindow(const std::string& name, unsigned int& contextId);
|
||||
|
||||
virtual void CloseWindow(unsigned int contextid);
|
||||
|
||||
/**
|
||||
* Get pick ray at given screen position
|
||||
*/
|
||||
dtEntity::Vec3f GetPickRay(unsigned int contextid, float x, float y, bool usePixels = false) const;
|
||||
|
||||
virtual bool GetWindowGeometry(unsigned int contextid, int& x, int& y, int& width, int& height) const;
|
||||
virtual bool SetWindowGeometry(unsigned int contextid, int x, int y, int width, int height);
|
||||
|
||||
virtual void SetFullscreen(unsigned int contextid, bool fullscreen);
|
||||
virtual bool GetFullscreen(unsigned int contextid) const;
|
||||
|
||||
virtual dtEntity::EntityId PickEntity(double x,
|
||||
double y,
|
||||
unsigned int nodemask,
|
||||
unsigned int contextid,
|
||||
bool usePixels = true) const;
|
||||
|
||||
void SetTraits(osg::GraphicsContext::Traits* traits) { mTraits = traits; }
|
||||
osg::GraphicsContext::Traits* GetTraits() const { return mTraits; }
|
||||
|
||||
virtual void SetShowCursor(unsigned int contextid, bool);
|
||||
|
||||
virtual dtEntity::Vec3d ConvertWorldToScreenCoords(unsigned int contextid, const dtEntity::Vec3d& coord);
|
||||
|
||||
/**
|
||||
* Should the window with given context id be continuously redrawn
|
||||
* or only by request? Default is on
|
||||
*/
|
||||
virtual void SetContinuousRedraw(unsigned int contextid, bool);
|
||||
|
||||
/**
|
||||
* If Continuous Redraw is off, request a redraw in next render traversal
|
||||
*/
|
||||
virtual void RequestRedraw(unsigned int contextid);
|
||||
|
||||
/**
|
||||
* Get intersections between start and end and add them to isects vector
|
||||
* @param start Start of intersection line
|
||||
* @param end End of intersection lnie
|
||||
* @param isects Vector return value for isect results
|
||||
* @param nodemask Bit mask, used for selecting nodes for intersection
|
||||
* @param layer Name of layer attach point component from which intersecition test will
|
||||
* be executed downwards (default: layer "default")
|
||||
* @return true if an intersection was found
|
||||
*/
|
||||
virtual bool GetIntersections(const dtEntity::Vec3d& start, const dtEntity::Vec3d& end,
|
||||
std::vector<dtEntity::WindowInterface::Intersection>& isects,
|
||||
unsigned int nodemask = dtEntity::NodeMasks::PICKABLE | dtEntity::NodeMasks::TERRAIN,
|
||||
dtEntity::StringId layer = dtEntity::StringId()
|
||||
) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
bool OpenWindowInternal(const std::string& name, unsigned int& contextId);
|
||||
|
||||
dtEntity::EntityManager* mEntityManager;
|
||||
|
||||
typedef std::map<unsigned int, WindowPos> WindowPosMap;
|
||||
WindowPosMap mWindowPositions;
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> mTraits;
|
||||
|
||||
};
|
||||
|
||||
inline OSGWindowInterface* GetOSGWindowInterface()
|
||||
{
|
||||
return static_cast<OSGWindowInterface*>(dtEntity::GetWindowInterface());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <osgManipulator/Dragger>
|
||||
#include <osgParticle/ParticleSystem>
|
||||
#include <osgParticle/ModularEmitter>
|
||||
#include <osgParticle/ModularProgram>
|
||||
#include <osgParticle/ParticleSystemUpdater>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class ParticleComponent
|
||||
: public dtEntityOSG::NodeComponent
|
||||
{
|
||||
|
||||
public:
|
||||
typedef dtEntityOSG::NodeComponent BaseClass;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
static const dtEntity::StringId AlphaRangeId;
|
||||
static const dtEntity::StringId ColorRangeMinId;
|
||||
static const dtEntity::StringId ColorRangeMaxId;
|
||||
static const dtEntity::StringId CounterId;
|
||||
static const dtEntity::StringId DebugOnId;
|
||||
static const dtEntity::StringId EmissiveParticlesId;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
static const dtEntity::StringId LifeTimeId;
|
||||
static const dtEntity::StringId LightingId;
|
||||
static const dtEntity::StringId MassId;
|
||||
static const dtEntity::StringId PlacerId;
|
||||
static const dtEntity::StringId SizeRangeId;
|
||||
static const dtEntity::StringId TextureFileId;
|
||||
static const dtEntity::StringId TextureUnitId;
|
||||
|
||||
static const dtEntity::StringId __SELECTED__Id;
|
||||
static const dtEntity::StringId BoxId;
|
||||
static const dtEntity::StringId CompositeId;
|
||||
static const dtEntity::StringId MultiSegmentId;
|
||||
static const dtEntity::StringId PointId;
|
||||
static const dtEntity::StringId SectorId;
|
||||
static const dtEntity::StringId SegmentId;
|
||||
|
||||
static const dtEntity::StringId XRangeId;
|
||||
static const dtEntity::StringId YRangeId;
|
||||
static const dtEntity::StringId ZRangeId;
|
||||
static const dtEntity::StringId CenterId;
|
||||
|
||||
static const dtEntity::StringId RandomRateCounterId;
|
||||
static const dtEntity::StringId ConstantRateCounterId;
|
||||
|
||||
static const dtEntity::StringId RateRangeId;
|
||||
static const dtEntity::StringId MinimumNumberOfParticlesToCreateId;
|
||||
static const dtEntity::StringId NumberOfParticlesPerSecondToCreateId;
|
||||
|
||||
static const dtEntity::StringId ShooterThetaRangeId;
|
||||
static const dtEntity::StringId ShooterPhiRangeId;
|
||||
static const dtEntity::StringId ShooterInitialSpeedRangeId;
|
||||
static const dtEntity::StringId ShooterInitialRotationalSpeedMinId;
|
||||
static const dtEntity::StringId ShooterInitialRotationalSpeedMaxId;
|
||||
|
||||
static const dtEntity::StringId ShapeId;
|
||||
static const dtEntity::StringId ShapePointId;
|
||||
static const dtEntity::StringId ShapeQuadId;
|
||||
static const dtEntity::StringId ShapeQuadTriangeStripId;
|
||||
static const dtEntity::StringId ShapeHexagonId;
|
||||
static const dtEntity::StringId ShapeLineId;
|
||||
|
||||
static const dtEntity::StringId OperatorsId;
|
||||
|
||||
static const dtEntity::StringId BounceOperatorId;
|
||||
static const dtEntity::StringId ForceOperatorId;
|
||||
|
||||
static const dtEntity::StringId FrictionId;
|
||||
static const dtEntity::StringId ResilienceId;
|
||||
static const dtEntity::StringId CutoffId;
|
||||
static const dtEntity::StringId DomainsId;
|
||||
static const dtEntity::StringId PlaneDomainId;
|
||||
static const dtEntity::StringId SphereDomainId;
|
||||
static const dtEntity::StringId ForceId;
|
||||
static const dtEntity::StringId NormalId;
|
||||
static const dtEntity::StringId DistId;
|
||||
static const dtEntity::StringId RadiusId;
|
||||
|
||||
|
||||
|
||||
ParticleComponent();
|
||||
virtual ~ParticleComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity &entity);
|
||||
virtual void OnRemovedFromEntity(dtEntity::Entity &entity);
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void SetTextureFile(const std::string& v) { mTextureFile.Set(v); }
|
||||
std::string GetTextureFile() const { return mTextureFile.Get(); }
|
||||
|
||||
void SetEmissiveParticles(bool v) { mEmissiveParticles.Set(v); }
|
||||
bool GetEmissiveParticles() const { return mEmissiveParticles.Get(); }
|
||||
|
||||
void SetDebugOn(bool v);
|
||||
bool GetDebugOn() const { return mDebugOnVal; }
|
||||
|
||||
void SetLighting(bool v) { mLighting.Set(v); }
|
||||
bool GetLighting() const { return mLighting.Get(); }
|
||||
|
||||
void SetTextureUnit(int v) { mTextureUnit.Set(v); }
|
||||
int GetTextureUnit() const { return mTextureUnit.Get(); }
|
||||
|
||||
void SetLifeTime(double v) { mLifeTime.Set(v); }
|
||||
double GetLifeTime() const { return mLifeTime.Get(); }
|
||||
|
||||
void SetMass(float v) { mMass.Set(v); }
|
||||
float GetMass() const { return mMass.Get(); }
|
||||
|
||||
void SetSizeRange(const osg::Vec2& v) { mSizeRange.Set(v); }
|
||||
osg::Vec2 GetSizeRange() const { return mSizeRange.Get(); }
|
||||
|
||||
|
||||
void SetCounter(const dtEntity::PropertyGroup&);
|
||||
dtEntity::PropertyGroup GetCounter() const;
|
||||
|
||||
void SetPlacer(const dtEntity::PropertyGroup&);
|
||||
dtEntity::PropertyGroup GetPlacer() const;
|
||||
|
||||
void SetShooterThetaRange(const osg::Vec2& v);
|
||||
osg::Vec2 GetShooterThetaRange() const;
|
||||
|
||||
void SetShooterPhiRange(const osg::Vec2& v);
|
||||
osg::Vec2 GetShooterPhiRange() const;
|
||||
|
||||
void SetShooterInitialSpeedRange(const osg::Vec2& v);
|
||||
osg::Vec2 GetShooterInitialSpeedRange() const;
|
||||
|
||||
void SetShooterInitialRotationalSpeedMin(const osg::Vec3& v);
|
||||
osg::Vec3 GetShooterInitialRotationalSpeedMin() const;
|
||||
|
||||
void SetShooterInitialRotationalSpeedMax(const osg::Vec3& v);
|
||||
osg::Vec3 GetShooterInitialRotationalSpeedMax() const;
|
||||
|
||||
void SetOperators(const dtEntity::PropertyArray& v);
|
||||
dtEntity::PropertyArray GetOperators() const;
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<osg::Geode> mGeode;
|
||||
osg::ref_ptr<osgParticle::ParticleSystem> mParticleSystem;
|
||||
osg::ref_ptr<osgParticle::ModularEmitter> mModularEmitter;
|
||||
osg::ref_ptr<osgParticle::ModularProgram> mProgram;
|
||||
|
||||
dtEntity::DynamicBoolProperty mDebugOn;
|
||||
bool mDebugOnVal;
|
||||
dtEntity::StringProperty mTextureFile;
|
||||
dtEntity::BoolProperty mEmissiveParticles;
|
||||
dtEntity::BoolProperty mEnabled;
|
||||
dtEntity::BoolProperty mLighting;
|
||||
dtEntity::IntProperty mTextureUnit;
|
||||
|
||||
dtEntity::DoubleProperty mLifeTime;
|
||||
dtEntity::FloatProperty mMass;
|
||||
dtEntity::Vec2Property mSizeRange;
|
||||
dtEntity::Vec2Property mAlphaRange;
|
||||
dtEntity::Vec4Property mColorRangeMin;
|
||||
dtEntity::Vec4Property mColorRangeMax;
|
||||
|
||||
dtEntity::DynamicGroupProperty mPlacer;
|
||||
dtEntity::GroupProperty mPlacerVal;
|
||||
dtEntity::DynamicGroupProperty mCounter;
|
||||
dtEntity::GroupProperty mCounterVal;
|
||||
|
||||
dtEntity::DynamicVec2Property mShooterThetaRange;
|
||||
dtEntity::DynamicVec2Property mShooterPhiRange;
|
||||
dtEntity::DynamicVec2Property mShooterInitialSpeedRange;
|
||||
dtEntity::DynamicVec3Property mShooterInitialRotationalSpeedMin;
|
||||
dtEntity::DynamicVec3Property mShooterInitialRotationalSpeedMax;
|
||||
|
||||
dtEntity::StringIdProperty mShape;
|
||||
|
||||
dtEntity::DynamicArrayProperty mOperators;
|
||||
dtEntity::ArrayProperty mOperatorsVal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ParticleSystem
|
||||
: public dtEntity::DefaultEntitySystem<ParticleComponent>
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<ParticleComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
ParticleSystem(dtEntity::EntityManager& em);
|
||||
~ParticleSystem();
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class PathComponent : public dtEntityOSG::NodeComponent
|
||||
{
|
||||
typedef dtEntityOSG::NodeComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId VertsId;
|
||||
static const dtEntity::StringId PathVisibleId;
|
||||
static const dtEntity::StringId VertsVisibleId;
|
||||
|
||||
typedef dtEntity::PropertyArray::size_type size_type;
|
||||
|
||||
PathComponent();
|
||||
virtual ~PathComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void SetPathsVisible(bool v) { mPathsVisible.Set(v); }
|
||||
bool GetPathsVisible() const { return mPathsVisible.Get(); }
|
||||
|
||||
void SetVertsVisible(bool v) { mVertsVisible.Set(v); }
|
||||
bool GetVertsVisible() const { return mVertsVisible.Get(); }
|
||||
|
||||
osg::Vec3 GetVertex(size_type index) const;
|
||||
void SetVertex(size_type index, const osg::Vec3& v);
|
||||
size_type GetNumVertices() const;
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::ArrayProperty mVerts;
|
||||
dtEntity::BoolProperty mPathsVisible;
|
||||
dtEntity::BoolProperty mVertsVisible;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PathSystem
|
||||
: public dtEntity::DefaultEntitySystem<PathComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<PathComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
PathSystem(dtEntity::EntityManager& em);
|
||||
~PathSystem();
|
||||
|
||||
dtEntity::Property* ScriptPickVertex(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptGetVertexWorldPosition(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetVertexWorldPosition(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptDuplicateVertex(const dtEntity::PropertyArgs& args);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osg/ShapeDrawable>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Adds a pickable shape to the transform of the entity
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT PickShapeComponent
|
||||
: public NodeComponent
|
||||
{
|
||||
public:
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId MinBoundsId;
|
||||
static const dtEntity::StringId MaxBoundsId;
|
||||
static const dtEntity::StringId VisibleId;
|
||||
|
||||
PickShapeComponent();
|
||||
virtual ~PickShapeComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
void SetMinBounds(const osg::Vec3& v);
|
||||
osg::Vec3 GetMinBounds() const { return mMinBoundsVal; }
|
||||
|
||||
void SetMaxBounds(const osg::Vec3& v);
|
||||
osg::Vec3 GetMaxBounds() const { return mMaxBoundsVal; }
|
||||
|
||||
void SetVisible(bool v);
|
||||
bool GetVisible() const;
|
||||
|
||||
private:
|
||||
|
||||
void UpdatePickShape();
|
||||
|
||||
// path to loaded script file
|
||||
dtEntity::StringProperty mMeshPathProperty;
|
||||
dtEntity::DynamicVec3Property mMinBounds;
|
||||
dtEntity::DynamicVec3Property mMaxBounds;
|
||||
dtEntity::DynamicBoolProperty mVisible;
|
||||
osg::ref_ptr<osg::Box> mBox;
|
||||
osg::Vec3 mMinBoundsVal;
|
||||
osg::Vec3 mMaxBoundsVal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT PickShapeSystem
|
||||
: public dtEntity::DefaultEntitySystem<PickShapeComponent>
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
PickShapeSystem(dtEntity::EntityManager& em);
|
||||
~PickShapeSystem();
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/transformcomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class PositionAttitudeTransform;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* holds a single PositionAttitude transform
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT PositionAttitudeTransformComponent
|
||||
: public TransformComponent
|
||||
{
|
||||
typedef TransformComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId PositionId;
|
||||
static const dtEntity::StringId AttitudeId;
|
||||
static const dtEntity::StringId ScaleId;
|
||||
|
||||
PositionAttitudeTransformComponent();
|
||||
|
||||
virtual ~PositionAttitudeTransformComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
const osg::PositionAttitudeTransform* GetPositionAttitudeTransform() const;
|
||||
osg::PositionAttitudeTransform* GetPositionAttitudeTransform();
|
||||
|
||||
dtEntity::Vec3d GetPosition() const;
|
||||
void SetPosition(const dtEntity::Vec3d& p);
|
||||
|
||||
dtEntity::Quat GetAttitude() const;
|
||||
void SetAttitude(const dtEntity::Quat& r);
|
||||
|
||||
dtEntity::Vec3d GetScale() const;
|
||||
void SetScale(const dtEntity::Vec3d& q);
|
||||
|
||||
virtual dtEntity::Vec3d GetTranslation() const { return GetPosition(); }
|
||||
virtual void SetTranslation(const dtEntity::Vec3d& t) { SetPosition(t); }
|
||||
|
||||
virtual dtEntity::Quat GetRotation() const { return GetAttitude(); }
|
||||
virtual void SetRotation(const dtEntity::Quat& q) { SetAttitude(q); }
|
||||
|
||||
virtual dtEntity::Matrix GetMatrix() const;
|
||||
virtual void SetMatrix(const dtEntity::Matrix& mat);
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicVec3dProperty mPosition;
|
||||
dtEntity::DynamicVec3dProperty mScale;
|
||||
dtEntity::DynamicQuatProperty mAttitude;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT PositionAttitudeTransformSystem
|
||||
: public dtEntity::DefaultEntitySystem<PositionAttitudeTransformComponent>
|
||||
{
|
||||
public:
|
||||
PositionAttitudeTransformSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::DefaultEntitySystem<PositionAttitudeTransformComponent>(em, TransformComponent::TYPE)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Program;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT ShaderComponent : public dtEntity::Component
|
||||
{
|
||||
|
||||
typedef dtEntity::Component BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId MaterialNamePrefixId;
|
||||
static const dtEntity::StringId TopLevelMaterialNameId;
|
||||
|
||||
ShaderComponent();
|
||||
virtual ~ShaderComponent();
|
||||
|
||||
void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
std::string GetMaterialNamePrefix() const { return mMaterialNamePrefix.Get(); }
|
||||
void SetMaterialNamePrefix(const std::string& s) { mMaterialNamePrefix.Set(s); }
|
||||
|
||||
std::string GetTopLevelMaterialName() const { return mTopLevelMaterialName.Get(); }
|
||||
void SetTopLevelMaterialName(const std::string& s) { mTopLevelMaterialName.Set(s); }
|
||||
|
||||
private:
|
||||
dtEntity::StringProperty mMaterialNamePrefix;
|
||||
dtEntity::StringProperty mTopLevelMaterialName;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT ShaderSystem
|
||||
: public dtEntity::DefaultEntitySystem<ShaderComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<ShaderComponent> BaseClass;
|
||||
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
ShaderSystem(dtEntity::EntityManager& em);
|
||||
~ShaderSystem();
|
||||
|
||||
void AddProgram(const std::string& name, osg::Program* prg);
|
||||
osg::Program* GetProgram(const std::string& name) const;
|
||||
|
||||
virtual bool CreateComponent(dtEntity::EntityId eid, dtEntity::Component*& component);
|
||||
|
||||
private:
|
||||
|
||||
typedef std::map<std::string, osg::ref_ptr<osg::Program> > ProgramMap;
|
||||
ProgramMap mPrograms;
|
||||
dtEntity::MessageFunctor mChangedMeshFunctor;
|
||||
|
||||
void OnChangedMesh(const dtEntity::Message& msg);
|
||||
void ApplyShader(dtEntity::EntityId);
|
||||
dtEntity::Property* ScriptAddProgram(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptAddUniform(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptRemoveUniform(const dtEntity::PropertyArgs& args);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osgShadow/ShadowTechnique>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
/**
|
||||
* Holds a single OSG node.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT ShadowComponent : public GroupComponent
|
||||
{
|
||||
typedef GroupComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
static const dtEntity::StringId EnabledId;
|
||||
static const dtEntity::StringId ShadowTechniqueId;
|
||||
static const dtEntity::StringId MinLightMarginId;
|
||||
static const dtEntity::StringId MaxFarPlaneId;
|
||||
static const dtEntity::StringId TexSizeId;
|
||||
static const dtEntity::StringId BaseTexUnitId;
|
||||
static const dtEntity::StringId ShadowTexUnitId;
|
||||
static const dtEntity::StringId ShadowTexCoordIndexId;
|
||||
static const dtEntity::StringId BaseTexCoordIndexId;
|
||||
static const dtEntity::StringId MapCountId;
|
||||
static const dtEntity::StringId MapResId;
|
||||
static const dtEntity::StringId DebugColorOnId;
|
||||
static const dtEntity::StringId MinNearSplitId;
|
||||
static const dtEntity::StringId MaxFarDistId;
|
||||
static const dtEntity::StringId MoveVCamFactorId;
|
||||
static const dtEntity::StringId PolyOffsetFactorId;
|
||||
static const dtEntity::StringId PolyOffsetUnitId;
|
||||
static const dtEntity::StringId LISPId;
|
||||
static const dtEntity::StringId PSSMId;
|
||||
static const dtEntity::StringId __SELECTED__Id;
|
||||
|
||||
static const dtEntity::StringId ShadowTypeId;
|
||||
|
||||
ShadowComponent();
|
||||
virtual ~ShadowComponent();
|
||||
|
||||
void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void SetShadowTechnique(const std::string name);
|
||||
|
||||
void SetEnabled(bool v) { mEnabled.Set(v); }
|
||||
bool GetEnabled() const { return mEnabled.Get(); }
|
||||
private:
|
||||
|
||||
dtEntity::Entity* mEntity;
|
||||
dtEntity::BoolProperty mEnabled;
|
||||
osg::ref_ptr<osgShadow::ShadowTechnique> mTechnique;
|
||||
|
||||
dtEntity::GroupProperty mShadowType;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT ShadowSystem
|
||||
: public dtEntity::DefaultEntitySystem<ShadowComponent>
|
||||
{
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
|
||||
ShadowSystem(dtEntity::EntityManager& em);
|
||||
virtual ~ShadowSystem();
|
||||
|
||||
void SetEnabled(bool);
|
||||
bool GetEnabled() const { return mEnabledVal; }
|
||||
|
||||
private:
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osg/Geode>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
/**
|
||||
* Holds a single OSG node.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT SkyBoxComponent : public GroupComponent
|
||||
{
|
||||
|
||||
typedef GroupComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId TextureUpId;
|
||||
static const dtEntity::StringId TextureDownId;
|
||||
static const dtEntity::StringId TextureNorthId;
|
||||
static const dtEntity::StringId TextureSouthId;
|
||||
static const dtEntity::StringId TextureEastId;
|
||||
static const dtEntity::StringId TextureWestId;
|
||||
|
||||
SkyBoxComponent();
|
||||
virtual ~SkyBoxComponent();
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual osg::Group* GetAttachmentGroup() const { return mDrawables; }
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Geode> mSkyboxGeode;
|
||||
dtEntity::StringProperty mTextureUp;
|
||||
dtEntity::StringProperty mTextureDown;
|
||||
dtEntity::StringProperty mTextureNorth;
|
||||
dtEntity::StringProperty mTextureSouth;
|
||||
dtEntity::StringProperty mTextureEast;
|
||||
dtEntity::StringProperty mTextureWest;
|
||||
osg::ref_ptr<osg::Group> mDrawables;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT SkyBoxSystem
|
||||
: public dtEntity::DefaultEntitySystem<SkyBoxComponent>
|
||||
{
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
SkyBoxSystem(dtEntity::EntityManager& em);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Loads a static mesh from a path
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT StaticMeshComponent
|
||||
: public NodeComponent
|
||||
{
|
||||
public:
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId MeshId;
|
||||
static const dtEntity::StringId CacheHintId;
|
||||
static const dtEntity::StringId OptimizeId;
|
||||
static const dtEntity::StringId IsTerrainId;
|
||||
|
||||
static const dtEntity::StringId CacheNoneId;
|
||||
static const dtEntity::StringId CacheAllId;
|
||||
static const dtEntity::StringId CacheNodesId;
|
||||
static const dtEntity::StringId CacheHardwareMeshesId;
|
||||
|
||||
StaticMeshComponent();
|
||||
virtual ~StaticMeshComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
// set existing geometry as static mesh
|
||||
void SetStaticMesh(osg::Node* node);
|
||||
|
||||
/**
|
||||
* return path of currently loaded mesh
|
||||
*/
|
||||
std::string GetMesh() const;
|
||||
|
||||
/**
|
||||
* Load mesh from path
|
||||
*/
|
||||
virtual void SetMesh(const std::string& path, dtEntity::StringId cacheHint = CacheAllId);
|
||||
|
||||
void SetCacheHint(dtEntity::StringId v) { mCacheHint.Set(v); }
|
||||
dtEntity::StringId GetCacheHint() const { return mCacheHint.Get(); }
|
||||
|
||||
bool GetOptimize() const { return mOptimize.Get(); }
|
||||
void SetOptimize(bool v) { mOptimize.Set(v); }
|
||||
|
||||
bool GetIsTerrain() const { return mIsTerrainVal; }
|
||||
void SetIsTerrain(bool v);
|
||||
|
||||
protected:
|
||||
|
||||
// path to loaded script file
|
||||
dtEntity::StringProperty mMeshPathProperty;
|
||||
dtEntity::StringIdProperty mCacheHint;
|
||||
dtEntity::BoolProperty mOptimize;
|
||||
dtEntity::DynamicBoolProperty mIsTerrain;
|
||||
bool mIsTerrainVal;
|
||||
std::string mLoadedMesh;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT StaticMeshSystem
|
||||
: public dtEntity::DefaultEntitySystem<StaticMeshComponent>
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
StaticMeshSystem(dtEntity::EntityManager& em);
|
||||
~StaticMeshSystem();
|
||||
|
||||
void OnResourceChanged(const dtEntity::Message& msg);
|
||||
|
||||
private:
|
||||
dtEntity::MessageFunctor mResourceChangedFunctor;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
#include <osgText/Text>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
class Entity;
|
||||
class TextLabelSystem;
|
||||
|
||||
class DTENTITY_OSG_EXPORT TextLabelComponent : public NodeComponent
|
||||
{
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
typedef std::vector<osg::ref_ptr<osgText::Text> >::size_type size_type;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId TextsId;
|
||||
static const dtEntity::StringId AlwaysOnTopId;
|
||||
static const dtEntity::StringId TextId;
|
||||
static const dtEntity::StringId ColorId;
|
||||
static const dtEntity::StringId BackdropColorId;
|
||||
static const dtEntity::StringId VisibleId;
|
||||
static const dtEntity::StringId HighlightedId;
|
||||
static const dtEntity::StringId OffsetId;
|
||||
static const dtEntity::StringId CharacterHeightId;
|
||||
static const dtEntity::StringId FontId;
|
||||
static const dtEntity::StringId AlignmentId;
|
||||
|
||||
TextLabelComponent();
|
||||
virtual ~TextLabelComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
|
||||
size_type GetNumTexts() const { return mTextEntries.size(); }
|
||||
void Create(size_type textid);
|
||||
void Destroy(size_type textid);
|
||||
|
||||
void ClearAll();
|
||||
|
||||
void SetText(size_type textid, const std::string&);
|
||||
std::string GetText(size_type textid) const;
|
||||
|
||||
void SetHighlighted(size_type textid, bool);
|
||||
bool GetHighlighted(size_type textid) const;
|
||||
|
||||
void SetFlashing(size_type textid, bool);
|
||||
bool GetFlashing(size_type textid) const;
|
||||
|
||||
void SetColor(size_type textid, const osg::Vec4&);
|
||||
osg::Vec4 GetColor(size_type textid) const;
|
||||
|
||||
void SetBackdropColor(size_type textid, const osg::Vec4&);
|
||||
osg::Vec4 GetBackdropColor(size_type textid) const;
|
||||
|
||||
void SetVisible(size_type textid, bool);
|
||||
bool GetVisible(size_type textid) const;
|
||||
|
||||
void SetFont(size_type textid, const std::string&);
|
||||
std::string GetFont(size_type textid) const;
|
||||
|
||||
void SetOffset(size_type textid, const osg::Vec3&);
|
||||
osg::Vec3 GetOffset(size_type textid) const;
|
||||
|
||||
void SetCharacterHeight(size_type textid, float);
|
||||
float GetCharacterHeight(size_type textid) const;
|
||||
|
||||
void SetAlignment(size_type textid, const std::string& str);
|
||||
std::string GetAlignment(size_type textid) const;
|
||||
|
||||
bool GetAlwaysOnTop() const { return mAlwaysOnTopVal; }
|
||||
void SetAlwaysOnTop(bool v);
|
||||
|
||||
private:
|
||||
|
||||
void SetTexts(const dtEntity::PropertyArray& texts);
|
||||
dtEntity::PropertyArray GetTexts() const;
|
||||
dtEntity::DynamicArrayProperty mTexts;
|
||||
dtEntity::ArrayProperty mTextsVal;
|
||||
dtEntity::DynamicBoolProperty mAlwaysOnTop;
|
||||
bool mAlwaysOnTopVal;
|
||||
typedef std::vector<osg::ref_ptr<osgText::Text> > TextEntries;
|
||||
TextEntries mTextEntries;
|
||||
TextLabelSystem* mTextLabelSystem;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT TextLabelSystem
|
||||
: public dtEntity::DefaultEntitySystem<TextLabelComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
static const dtEntity::StringId EnabledId;
|
||||
typedef dtEntity::DefaultEntitySystem<TextLabelComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
TextLabelSystem(dtEntity::EntityManager& em);
|
||||
|
||||
void SetEnabled(bool v);
|
||||
bool GetEnabled() const;
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
dtEntity::Property* ScriptCreate(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptDestroy(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetText(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetOffset(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetAlignment(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetColor(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetBackdropColor(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetHighlighted(const dtEntity::PropertyArgs& args);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Program>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class TextureLabelSystem;
|
||||
|
||||
class DTENTITY_OSG_EXPORT TextureLabelComponent : public NodeComponent
|
||||
{
|
||||
|
||||
friend class TextureLabelSystem;
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId OffsetId;
|
||||
static const dtEntity::StringId PathId;
|
||||
static const dtEntity::StringId ColorId;
|
||||
static const dtEntity::StringId MaxSizeId;
|
||||
static const dtEntity::StringId MinSizeId;
|
||||
static const dtEntity::StringId DistanceAttenuationId;
|
||||
static const dtEntity::StringId VisibleId;
|
||||
static const dtEntity::StringId AlwaysOnTopId;
|
||||
static const dtEntity::StringId AddConnectingLineId;
|
||||
|
||||
TextureLabelComponent();
|
||||
virtual ~TextureLabelComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
std::string GetPath() const { return mPath.Get(); }
|
||||
|
||||
// call OnFinished...() to apply
|
||||
void SetPath(const std::string& path) { mPath.Set(path); }
|
||||
|
||||
osg::Geode* GetGeode() const;
|
||||
|
||||
osg::Vec3 GetOffset() const { return mOffsetVal; }
|
||||
void SetOffset(const osg::Vec3& o);
|
||||
|
||||
void SetMaxSize(unsigned int v) { mMaxSize.Set(v); }
|
||||
unsigned int GetMaxSize() const { return mMaxSize.Get(); }
|
||||
|
||||
void SetMinSize(unsigned int v) { mMinSize.Set(v); }
|
||||
unsigned int GetMinSize() const { return mMinSize.Get(); }
|
||||
|
||||
void SetDistanceAttenuation(const osg::Vec3& v) { mDistanceAttenuation.Set(v); }
|
||||
osg::Vec3 GetDistanceAttenuation() const { return mDistanceAttenuation.Get(); }
|
||||
|
||||
osg::Vec4 GetColor() const { return mColorVal; }
|
||||
void SetColor(const osg::Vec4& v);
|
||||
|
||||
void SetVisible(bool v);
|
||||
bool GetVisible() const;
|
||||
|
||||
bool GetAlwaysOnTop() const { return mAlwaysOnTop.Get(); }
|
||||
void SetAlwaysOnTop(bool v) { mAlwaysOnTop.Set(v); }
|
||||
|
||||
osg::Uniform* GetColorUniform() const { return mColorUniform; }
|
||||
private:
|
||||
|
||||
osg::ref_ptr<osg::Vec4Array> mColorArray;
|
||||
osg::ref_ptr<osg::Geometry> mDotGeometry;
|
||||
dtEntity::DynamicVec3Property mOffset;
|
||||
osg::Vec3 mOffsetVal;
|
||||
dtEntity::DynamicVec4Property mColor;
|
||||
osg::Vec4 mColorVal;
|
||||
dtEntity::StringProperty mPath;
|
||||
dtEntity::UIntProperty mMinSize;
|
||||
dtEntity::UIntProperty mMaxSize;
|
||||
dtEntity::Vec3Property mDistanceAttenuation;
|
||||
dtEntity::DynamicBoolProperty mVisible;
|
||||
dtEntity::BoolProperty mAlwaysOnTop;
|
||||
TextureLabelSystem* mLabelSystem;
|
||||
osg::ref_ptr<osg::Uniform> mColorUniform;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT TextureLabelSystem
|
||||
: public dtEntity::DefaultEntitySystem<TextureLabelComponent>
|
||||
{
|
||||
static const dtEntity::StringId EnabledId;
|
||||
typedef dtEntity::DefaultEntitySystem<TextureLabelComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
TextureLabelSystem(dtEntity::EntityManager& em);
|
||||
~TextureLabelSystem();
|
||||
|
||||
osg::StateSet* GetSymbolStateset(const std::string& symbolpath, TextureLabelComponent& component);
|
||||
|
||||
void SetupLabel(TextureLabelComponent& component);
|
||||
|
||||
void SetEnabled(bool v);
|
||||
bool GetEnabled() const;
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
osg::ref_ptr<osg::Program> mProgram;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* abstract base class for transform components
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT TransformComponent
|
||||
: public GroupComponent
|
||||
{
|
||||
typedef GroupComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
TransformComponent(osg::Transform* trans);
|
||||
|
||||
virtual ~TransformComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
virtual dtEntity::Vec3d GetTranslation() const = 0;
|
||||
virtual void SetTranslation(const dtEntity::Vec3d&) = 0;
|
||||
|
||||
virtual dtEntity::Vec3d GetScale() const { return dtEntity::Vec3d(1,1,1); }
|
||||
virtual void SetScale(const dtEntity::Vec3d&) {}
|
||||
|
||||
virtual dtEntity::Quat GetRotation() const = 0;
|
||||
virtual void SetRotation(const dtEntity::Quat&) = 0;
|
||||
|
||||
virtual dtEntity::Matrix GetMatrix() const
|
||||
{
|
||||
dtEntity::Matrix matrix;
|
||||
matrix.setTrans(GetTranslation());
|
||||
matrix.setRotate(GetRotation());
|
||||
return matrix;
|
||||
}
|
||||
|
||||
virtual void SetMatrix(const dtEntity::Matrix& mat)
|
||||
{
|
||||
SetTranslation(mat.getTrans());
|
||||
SetRotation(mat.getRotate());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class DTENTITY_OSG_EXPORT TransformSystem
|
||||
: public dtEntity::EntitySystem
|
||||
{
|
||||
public:
|
||||
TransformSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::EntitySystem(em)
|
||||
{
|
||||
}
|
||||
|
||||
dtEntity::ComponentType GetComponentType() const { return TransformComponent::TYPE; }
|
||||
};
|
||||
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
libdtEntity.so.2
|
||||
BIN
Binary file not shown.
+1
@@ -0,0 +1 @@
|
||||
libdtEntity.so.0.1.1
|
||||
+1
@@ -0,0 +1 @@
|
||||
libdtEntityOSG.so.2
|
||||
BIN
Binary file not shown.
+1
@@ -0,0 +1 @@
|
||||
libdtEntityOSG.so.0.1.1
|
||||
Reference in new issue
Block a user