example.cpp

This is an advanced example on the basic usage of the AwV4 encapsulation.

00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <time.h>
00004 #include <signal.h>
00005 #include <memory>
00006 #if defined(LINUX)
00007 # include <netdb.h>
00008 # include <sys/socket.h>
00009 # include <fcntl.h>
00010 # include <netinet/in.h>
00011 # include <sys/time.h>
00012 # include <arpa/inet.h>
00013 # include <unistd.h>
00014 #endif
00015 
00016 #include "Aw.h"
00017 #include "AwV4.h"
00018 
00019 /*---------------------------------------------------------------------------*/
00020 
00021 /* Specify a universe host here */
00022 #define UNIVERSE_HOST "auth.activeworlds.com"
00023 
00024 /* Specify a universe port here */
00025 #define UNIVERSE_PORT (6670)
00026 
00027 /* Specify what world to test in */
00028 #define LOGIN_WORLD "myworld"
00029 
00030 /* Specify a citnum to login with */
00031 #define LOGIN_CITNUM (123456)
00032 
00033 /* Specify the above citnum's privilege password */
00034 #define LOGIN_PPW "mypass"
00035 
00036 /*---------------------------------------------------------------------------*/
00037 
00038 #if defined(_MSC_VER)
00039 # undef AW_STATIC
00040 # pragma comment(lib, "aw.lib")
00041 #endif
00042 
00043 void exit_aw_error(char* method, int rc)
00044 {
00045         printf("%s failed: reason %d\n", method, rc);
00046         exit(rc);
00047 }
00048 
00049 template<typename SDK_T, class CLASS_T>
00050 void do_build(CLASS_T& obj)
00051 {
00052         SDK_T* data = obj.GetObjectData();
00053         AwV4::PrepareToBuild(data);
00054 
00055         aw_string_set(AW_OBJECT_MODEL, "rcube.rwx");
00056         aw_int_set(AW_OBJECT_X, -9000);
00057         aw_int_set(AW_OBJECT_Y, 0);
00058         aw_int_set(AW_OBJECT_Z, -9000);
00059         aw_int_set(AW_OBJECT_OWNER, LOGIN_CITNUM);
00060         aw_object_add();
00061 
00062         free(data);
00063 }
00064 
00065 void zone_test()
00066 {
00067         AwV4::Zone zone;
00068 
00069         AwV4::SimpleString& camtag = zone.CameraTag();
00070         camtag = "rcube";
00071 
00072         unsigned short& flg = zone.Flags();
00073         flg |= AW_ZONE_FLAG_VISIBLE;
00074 
00075         do_build<aw_object_data_zone, AwV4::Zone>(zone);
00076 }
00077 
00078 void particle_test()
00079 {
00080         AwV4::ParticleEmitter emitter;
00081 
00082         // this particle is dr. squailboont's infamous random fountain
00083 
00084         AwV4::SimpleString& assets = emitter.AssetList();
00085         assets = "c_flare1,c_flare2,c_nebula,c_portal,c_soft1,c_spotlight,c_spotlight2,c_spotlight3,c_star,c_star2,c_sun,c_sun2";
00086 
00087         emitter.ColorStart() = 0xFFFFFF;
00088         emitter.ReleaseMin() = 20;
00089         emitter.ReleaseMax() = 90;
00090         emitter.ReleaseCount() = 6;
00091         emitter.Lifespan() = 8000;
00092         emitter.FadeIn() = 500;
00093         emitter.FadeOut() = 7000;
00094         emitter.RenderStyle() = AW_PARTICLE_DRAW_BRIGHT;
00095 
00096         aw_type_vector_range& speed = emitter.Speed();
00097         speed.min.x = -3.0f;
00098         speed.min.y =  5.0f;
00099         speed.min.z = -3.0f;
00100         speed.max.x =  3.0f;
00101         speed.max.y =  5.0f;
00102         speed.max.z =  3.0f;
00103 
00104         aw_type_vector_range& accel = emitter.Accel();
00105         accel.min.y = -2.5f;
00106         accel.max.y = -2.5f;
00107 
00108         aw_type_vector_range& size = emitter.Size();
00109         size.min.x = 0.2f;
00110         size.min.y = 0.2f;
00111         size.min.z = 2.0f;
00112         size.max.x = 1.6f;
00113         size.max.y = 1.6f;
00114         size.max.z = 2.0f;
00115 
00116         do_build<aw_object_data_particles, AwV4::ParticleEmitter>(emitter);
00117 }
00118 
00119 void mover_test()
00120 {
00121         AwV4::Mover mov;
00122 
00123         mov.Type() = AW_MOVER_TYPE_PASSIVE;
00124         mov.Name() = "lawlz";
00125         mov.BumpName() = "omg";
00126         mov.AddWaypoint(new AwV4::Mover::Waypoint(0, 10, 0, 0, 0, 0, static_cast<unsigned short>(2.0f * 100), 255));
00127 
00128         do_build<aw_object_data_mover, AwV4::Mover>(mov);
00129 }
00130 
00131 void do_v4_test()
00132 {
00133 //      zone_test();
00134 //      particle_test();
00135         mover_test();
00136 }
00137 
00138 int main(int, char**)
00139 {
00140         aw_init(AW_BUILD);
00141 
00142         int rc = 0;
00143 
00144         if ((rc = aw_init(AW_BUILD)))
00145                 exit_aw_error("aw_init", rc);
00146 
00147         if ((rc = aw_create(UNIVERSE_HOST, UNIVERSE_PORT, 0)))
00148                 exit_aw_error("aw_create", rc);
00149 
00150         aw_int_set(AW_LOGIN_OWNER, LOGIN_CITNUM);
00151         aw_string_set(AW_LOGIN_PRIVILEGE_PASSWORD, LOGIN_PPW);
00152         aw_string_set(AW_LOGIN_NAME, "awv4test");
00153         aw_string_set(AW_LOGIN_APPLICATION, "AwV4 Library Test Program");
00154 
00155         if ((rc = aw_login()))
00156                 exit_aw_error("aw_login", rc);
00157 
00158         aw_bool_set(AW_ENTER_GLOBAL, true);
00159 
00160         if ((rc = aw_enter(LOGIN_WORLD)))
00161                 exit_aw_error("aw_enter", rc);
00162 
00163         aw_state_change();
00164         aw_wait(500);
00165 
00166         aw_say("Barnacles!");
00167         do_v4_test();
00168 
00169         aw_term();
00170 
00171         return 0;
00172 }
00173 
00174 /*---------------------------------------------------------------------------*/

Generated on Sun Mar 4 05:45:57 2007 for AwV4 by  doxygen 1.5.1-p1