// default constructor with owner GAnimTRSNode2D::GAnimTRSNode2D(const GElement* Owner) : GAnimElement(Owner) { // gPivotPosition is automatically set to (0, 0) gPivotRotation = 0; gPivotScale.Set(1, 1); gFather = NULL; gCustomData = NULL; // add TRS properties GBool alreadyExists; GUInt32 index; GProperty *tmpProp = AddProperty("transform", G_PROPERTY_CLASSID, GKeyValue(), alreadyExists, index); if (tmpProp) { G_ASSERT(alreadyExists == G_FALSE); // default value for "x" and "y" sub-properties will be set automatically to 0 tmpProp->AddProperty("position", G_TWOHERMITEPROPERTY1D_CLASSID, GKeyValue(), alreadyExists, index); G_ASSERT(alreadyExists == G_FALSE); tmpProp->AddProperty("rotation", G_HERMITEPROPERTY1D_CLASSID, GKeyValue((GReal)0), alreadyExists, index); G_ASSERT(alreadyExists == G_FALSE); // we must impose a default value of 1 to "x" and "y" sub-properties GProperty *p = tmpProp->AddProperty("scale", G_TWOHERMITEPROPERTY1D_CLASSID, GKeyValue(), alreadyExists, index); G_ASSERT(alreadyExists == G_FALSE); p->Property("x")->SetDefaultValue(GKeyValue((GReal)1)); p->Property("y")->SetDefaultValue(GKeyValue((GReal)1)); } }
GError GAnimTRSNode2D::SetScale(const GTimeValue TimePos, const GVectBase<GReal, 2>& RelScale) { GError err; GProperty *tmpProp = Property("transform"); // this can be the case of a curve not created through a kernel if (!tmpProp) { err = G_MISSING_KERNEL; } else { // extract position track GProperty *scaleProp = tmpProp->Property("scale"); G_ASSERT(scaleProp); GKeyValue tmpValue; tmpValue.SetTimePosition(TimePos); // set "x" property tmpProp = scaleProp->Property("x"); G_ASSERT(tmpProp != NULL); tmpValue.SetValue(RelScale[G_X]); err = tmpProp->SetValue(tmpValue, TimePos, G_ABSOLUTE_VALUE); if (err != G_NO_ERROR) return err; // set "y" property tmpProp = scaleProp->Property("y"); G_ASSERT(tmpProp != NULL); tmpValue.SetValue(RelScale[G_Y]); err = tmpProp->SetValue(tmpValue, TimePos, G_ABSOLUTE_VALUE); } return err; }
// clone properties GError GAnimElement::CloneProperties(const GAnimElement& Source) { const GProperty *srcProp; GProperty *tmpProp; GBool alreadyExists; GUInt32 i; GError err; G_ASSERT(this != &Source); GDynArray<GProperty *>::const_iterator it = Source.gProperties.begin(); // clone every property for (; it != Source.gProperties.end(); ++it) { srcProp = *it; G_ASSERT(srcProp != NULL); tmpProp = AddProperty(srcProp->Name(), srcProp->ClassID(), GKeyValue(), alreadyExists, i); if (tmpProp) { // lets do copy err = tmpProp->CopyFrom(*srcProp); if (err != G_NO_ERROR) RemoveProperty(i); } else G_ASSERT(tmpProp != NULL); } return G_NO_ERROR; }
void Label::setAttachPoint(int p_attachPoint) { G_ASSERT(!((p_attachPoint & AP_LEFT) && (p_attachPoint & AP_RIGHT)) && "bad value"); G_ASSERT(!((p_attachPoint & AP_TOP) && (p_attachPoint & AP_BOTTOM)) && "bad value"); m_attachPoint = p_attachPoint; }
GVectBase<GReal, 2> GAnimTRSNode2D::Scale(const GTimeValue TimePos, const GSpaceSystem Space, GTimeInterval& ValidInterval) const { GProperty *tmpProp = Property("transform"); if (!tmpProp) return GVector2(1, 1); tmpProp = tmpProp->Property("scale"); G_ASSERT(tmpProp); GTimeInterval tmpValid = G_FOREVER_TIMEINTERVAL; GKeyValue xValue, yValue; // extract scale GProperty *xProp = tmpProp->Property("x"); GProperty *yProp = tmpProp->Property("y"); G_ASSERT(xProp != NULL); G_ASSERT(yProp != NULL); GError xErr = xProp->Value(xValue, tmpValid, TimePos, G_ABSOLUTE_VALUE); GError yErr = yProp->Value(yValue, tmpValid, TimePos, G_ABSOLUTE_VALUE); if (xErr != G_NO_ERROR || yErr != G_NO_ERROR) return GVector2(1, 1); ValidInterval = tmpValid; // take care of father if (gFather && Space == G_WORLD_SPACE) { GVectBase<GReal, 2> retValue(xValue.RealValue(), yValue.RealValue()); retValue += gFather->Scale(TimePos, G_WORLD_SPACE, tmpValid); ValidInterval &= tmpValid; return retValue; } return GVectBase<GReal, 2>(xValue.RealValue(), yValue.RealValue()); }
GPoint2 GAnimTRSNode2D::Position(const GTimeValue TimePos, const GSpaceSystem Space, GTimeInterval& ValidInterval) const { GProperty *tmpProp = Property("transform"); if (!tmpProp) return GPoint2(0, 0); tmpProp = tmpProp->Property("position"); G_ASSERT(tmpProp); GTimeInterval tmpValid = G_FOREVER_TIMEINTERVAL; GKeyValue xValue, yValue; // extract translation GProperty *xProp = tmpProp->Property("x"); GProperty *yProp = tmpProp->Property("y"); G_ASSERT(xProp != NULL); G_ASSERT(yProp != NULL); // build translation factor GError xErr = xProp->Value(xValue, tmpValid, TimePos, G_ABSOLUTE_VALUE); GError yErr = yProp->Value(yValue, tmpValid, TimePos, G_ABSOLUTE_VALUE); if (xErr != G_NO_ERROR || yErr != G_NO_ERROR) return GPoint2(0, 0); ValidInterval = tmpValid; // take care of father if (gFather && Space == G_WORLD_SPACE) { GPoint2 retValue(xValue.RealValue(), yValue.RealValue()); retValue += gFather->Position(TimePos, G_WORLD_SPACE, tmpValid); ValidInterval &= tmpValid; return retValue; } return GPoint2(xValue.RealValue(), yValue.RealValue()); }
void ShaderImpl::begin(CL_GraphicContext &p_gc) { G_ASSERT(m_initialized); G_ASSERT(!m_began); // new texture m_drawRect = m_parent->getDrawRect(m_boundRect); m_texture = CL_Texture(p_gc, m_drawRect.get_width(), m_drawRect.get_height()); // attach frame buffer m_frameBuffer.attach_color_buffer(0, m_texture); p_gc.set_frame_buffer(m_frameBuffer); // clear to transparent p_gc.clear(CL_Colorf::transparent); // set proper matrix p_gc.push_modelview(); // get scaling in count const CL_Mat4f &matrix = p_gc.get_modelview(); const float scaleX = matrix[0]; const float scaleY = matrix[5]; p_gc.mult_translate(-m_drawRect.left / scaleX, -m_drawRect.top / scaleY); m_began = true; }
void GOpenGLBoard::GrabFrameBuffer(const GAABox2& LogicBox, GLGrabbedRect& Shot) { GLDisableShaders(); GReal left, right, bottom, top; Projection(left, right, bottom, top); if (LogicBox.Min()[G_X] > left) left = LogicBox.Min()[G_X]; if (LogicBox.Max()[G_X] < right) right = LogicBox.Max()[G_X]; if (LogicBox.Min()[G_Y] > bottom) bottom = LogicBox.Min()[G_Y]; if (LogicBox.Max()[G_Y] < top) top = LogicBox.Max()[G_Y]; GAABox2 tmpBox(GPoint2(left, bottom), GPoint2(right, top)); GPoint<GInt32, 2> p0 = LogicalToPhysicalInt(tmpBox.Min()); GPoint<GInt32, 2> p1 = LogicalToPhysicalInt(tmpBox.Max()); p0[G_X] -= 1; p0[G_Y] -= 1; p1[G_X] += 1; p1[G_Y] += 1; GGenericAABox<GInt32, 2> intBox(p0, p1); GUInt32 width = (GUInt32)GMath::Abs(p1[G_X] - p0[G_X]); GUInt32 height = (GUInt32)GMath::Abs(p1[G_Y] - p0[G_Y]); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); UpdateGrabBuffer(width, height, Shot); G_ASSERT(Shot.TexName > 0); G_ASSERT(Shot.TexWidth > 0 && Shot.TexHeight > 0); G_ASSERT(Shot.TexWidth >= width && Shot.TexHeight >= height); SELECT_AND_DISABLE_TUNIT(1) SELECT_AND_DISABLE_TUNIT(0) glEnable(Shot.Target); glBindTexture(Shot.Target, Shot.TexName); glCopyTexSubImage2D(Shot.Target, 0, 0, 0, (GLint)intBox.Min()[G_X], (GLint)intBox.Min()[G_Y], (GLsizei)width, (GLsizei)height); Shot.Width = width; Shot.Height = height; Shot.IsEmpty = G_FALSE; Shot.gNotExpandedLogicBox = tmpBox; GPoint2 q0 = PhysicalToLogical(p0); GPoint2 q1 = PhysicalToLogical(p1); Shot.gExpandedLogicBox.SetMinMax(q0, q1); SELECT_AND_DISABLE_TUNIT(0) glPixelStorei(GL_PACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); }
/** * @brief Realization::clear */ void Realization::clear() { Entity::SharedClass head = std::dynamic_pointer_cast<Entity::Class>(G_ASSERT(headClass())); Q_ASSERT_X(head, "Realization::clear", "head class not found or not Class"); for (auto method : m_Methods) { head->removeMethods(method->name()); G_ASSERT(tailClass())->removeMethods(method->name()); } }
void RaceScene::initializeOnline(const CL_String &p_hostname, int p_port) { G_ASSERT(p_hostname.length() > 0); G_ASSERT(p_port > 0 && p_port <= 0xFFFF); if (!m_initialized) { m_logic = new Race::OnlineRaceLogic(p_hostname, p_port); initCommon(); } }
/** * @brief View::addElement * @param type * @param eventPos */ void View::addElement(entity::KindOfType kindOfType, const QPoint &eventPos) { if (auto pr = project()) { auto projectDb = G_ASSERT(pr->database()); auto scope = G_ASSERT(projectDb->scope(common::ID::projectScopeID())); if (auto stack = pr->commandsStack()) { auto pos = mapToScene(eventPos); if (auto cmd = std::make_unique<commands::CreateEntity>(kindOfType, scope->id(), pos)) stack->push(cmd.release()); } } else { qWarning() << Q_FUNC_INFO << ": there is no project."; } }
/** * @brief Realization::make */ void Realization::make() { Entity::SharedMethod m; Entity::SharedClass head = std::dynamic_pointer_cast<Entity::Class>(G_ASSERT(headClass())); Q_ASSERT_X(head, "Realization::make", "head class not found or not Class"); for (auto &&method : m_Methods) { m = std::make_shared<Entity::ClassMethod>(*method.get()); m->setRhsIdentificator(Entity::RhsIdentificator::PureVirtual); head->addExistsMethod(m); m = std::make_shared<Entity::ClassMethod>(*method.get()); m->setRhsIdentificator(Entity::RhsIdentificator::Override); G_ASSERT(tailClass())->addExistsMethod(m); } }
/* * Event source function - destructor of the source, called * before the source object destroyed. we decrease the reference * count of ioc channel since the source object owes the count * of it. */ static void hm_watch_finalize(GSource *source) { HmWatch *watch; G_ASSERT(source != NULL); g_atomic_int_add(&total_watch_count, -1); watch = (HmWatch*)source; hm_debug( "Net IO '%p' finalized. total %d left.", NET_IO(watch), g_atomic_int_get(&total_watch_count) ); if (watch->funcs && watch->funcs->finalize) { (*watch->funcs->finalize)(watch); } hm_watch_destroy_private(watch->priv_data); watch->priv_data = NULL; if (watch->conn) /* we need to flush the rest of data!!! */ { hm_connection_close(watch->conn); } if (watch->buffer) { hm_net_buf_free(watch->buffer); } g_mutex_free(watch->lock); }
OnlineRaceLogic::OnlineRaceLogic(const CL_String &p_host, int p_port) : m_initialized(false), m_host(p_host), m_port(p_port), m_client(&Game::getInstance().getNetworkConnection()), m_localPlayer(Game::getInstance().getPlayer()), m_voteRunning(false) { G_ASSERT(p_port > 0 && p_port <= 0xFFFF); m_client->setServerAddr(m_host); m_client->setServerPort(m_port); // connect signal and slots from player's car Car &car = m_localPlayer.getCar(); m_slots.connect(car.sig_inputChanged(), this, &OnlineRaceLogic::onInputChange); // connect signals and slots from client m_slots.connect(m_client->sig_connected(), this, &OnlineRaceLogic::onConnected); m_slots.connect(m_client->sig_disconnected(), this, &OnlineRaceLogic::onDisconnected); m_slots.connect(m_client->sig_goodbyeReceived(), this, &OnlineRaceLogic::onGoodbye); m_slots.connect(m_client->sig_playerJoined(), this, &OnlineRaceLogic::onPlayerJoined); m_slots.connect(m_client->sig_playerLeaved(), this, &OnlineRaceLogic::onPlayerLeaved); m_slots.connect(m_client->sig_gameStateReceived(), this, &OnlineRaceLogic::onGameState); m_slots.connect(m_client->sig_carStateReceived(), this, &OnlineRaceLogic::onCarState); m_slots.connect(m_client->sig_raceStartReceived(), this, &OnlineRaceLogic::onRaceStart); m_slots.connect(m_client->sig_voteStarted(), this, &OnlineRaceLogic::onVoteStarted); m_slots.connect(m_client->sig_voteEnded(), this, &OnlineRaceLogic::onVoteEnded); m_slots.connect(m_client->sig_voteTickReceived(), this, &OnlineRaceLogic::onVoteTick); }
void OnlineRaceLogic::onPlayerLeaved(const CL_String &p_name) { // get the player Player &player = getPlayer(p_name); // remove from level getLevel().removeCar(&player.getCar()); // remove from game removePlayer(player); TPlayerList::iterator itor; bool found = false; for (itor = m_remotePlayers.begin(); itor != m_remotePlayers.end(); ++itor) { if (reinterpret_cast<unsigned> (itor->get()) == reinterpret_cast<unsigned> (&player)) { m_remotePlayers.erase(itor); found = true; break; } } G_ASSERT(found); display(cl_format("Player %1 leaved", p_name)); }
/** * @brief RelationFactory::make * @param relType * @param tail * @param head * @param addToScene * @return */ SharedRelation RelationFactory::make(RelationType relType, const common::ID &tail, const common::ID &head, CreationOptions options) const { if (auto pr = G_ASSERT(project())) { if (G_ASSERT(pr->database() && project()->globalDatabase())) { if (auto maker = G_ASSERT(relationMaker[relType])) { if (auto relation = maker(tail, head, {pr->database(), pr->globalDatabase()})) { addRelation(relation, pr->database(), scene(), options); return relation; } } } } return nullptr; }
void RaceScene::updateCarTurn() { G_ASSERT(m_initialized); Race::Car &car = Game::getInstance().getPlayer().getCar(); car.setTurn((int) -m_turnLeft + (int) m_turnRight); }
__export NmpIO * nmp_io_new(NmpConnection *conn, NmpPacketProto *proto, NmpIOFuncs *funcs, gsize size) { NmpIO *io; G_ASSERT(conn != NULL && proto != NULL && funcs != NULL); if (nmp_connection_is_blocked(conn)) { nmp_warning( "Net create io on blocked connection '%p'.", conn ); return NULL; } io = (NmpIO*)nmp_watch_create( conn, &nmp_io_watch_funcs, size); if (!io) { nmp_warning( "Net create watch failed." ); return NULL; } nmp_io_initialize(io, 0); io->proto = proto; io->funcs = funcs; return io; }
__export void hm_watch_unref(HmWatch *watch) { G_ASSERT(watch != NULL); g_source_unref((GSource*)watch); }
// move all rotation keys by an additive offset angle (expressed in radiant) void GAnimTRSNode2D::OffsetRotationTrack(const GReal OffsetAngle) { GProperty *tmpProp = Property("transform"), *rotProp; GUInt32 i, j; GKeyValue tmpKey; if (!tmpProp) return; rotProp = tmpProp->Property("rotation"); G_ASSERT(rotProp != NULL); j = rotProp->KeysCount(); if (j == 0) { tmpKey = rotProp->DefaultValue(); tmpKey.SetValue(OffsetAngle + tmpKey.RealValue()); rotProp->SetDefaultValue(tmpKey); } else { for (i = 0; i < j; ++i) { rotProp->Key(i, tmpKey); rotProp->SetValue(tmpKey.RealValue() + OffsetAngle); rotProp->SetKey(i, tmpKey); } } }
static void nmp_sysmsg_default_priv_des(gpointer priv, gsize size) { G_ASSERT(priv != NULL); nmp_mem_kfree(priv, size); }
gint nmp_sysmsg_set_userdata(NmpSysMsg *msg, gpointer data, gsize size) { gpointer p; G_ASSERT(NMP_IS_SYSMSG(msg)); if (data && size) { p = nmp_mem_kalloc(size); if (!p) { return -ENOMEM; } if (msg->user_data) { nmp_mem_kfree(msg->user_data, msg->user_size); } msg->user_data = p; msg->user_size = size; memcpy(msg->user_data, data, size); return 0; } return -EINVAL; }
__export gint hm_net_kill_io(HmNet *net, HmNetIO *net_io) { G_ASSERT(net != NULL && net_io != NULL); return _hm_net_kill_io(net, net_io, 0, 0); }
//------------------------------------------------------------ GError QGLWidgetTest::LoadAndTesselateGlyphs(const GString& FileName, const GReal Deviation) { if (!FileUtils::FileExists(StrUtils::ToAscii(FileName))) return G_FILE_NOT_FOUND; // create the font GFont2D *font = (GFont2D *)gKernel->CreateNew(G_FONT2D_CLASSID); if (!font) return G_MEMORY_ERROR; // load the font, normalizing points into [0;1]x[0;1] range (scale=0 option) GError err = font->Load(StrUtils::ToAscii(FileName), "scale=0"); if (err != G_NO_ERROR) return err; // flatten and tessellate every character GInt32 i, j = font->CharsCount(); for (i = 0; i < j; ++i) { const GFontChar2D *fontChar = font->CharByIndex(i); G_ASSERT(fontChar != NULL); if (!fontChar->IsComposite()) { GTesselatedGlyph *tessGlyph = new(std::nothrow) GTesselatedGlyph(fontChar, Deviation); if (tessGlyph) { gTesselatedGlyphs.push_back(tessGlyph); } } } // delete font from memory and return delete font; return G_NO_ERROR; }
gint nmp_mod_mds_setup(NmpAppMod *am_self) { gint err; NmpModAccess *ma_self; NmpModMds *self; struct sockaddr_in sin; G_ASSERT(am_self != NULL); self = (NmpModMds*)am_self; ma_self = (NmpModAccess*)am_self; bzero(&sin, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(JPFCMS_MDU_PORT); sin.sin_addr.s_addr = INADDR_ANY; nmp_mod_acc_init_net(ma_self, &nmp_packet_proto, &nmp_xml_proto); self->listen_io = nmp_mod_acc_create_listen_io( ma_self, (struct sockaddr*)&sin, &err ); if (!self->listen_io) { nmp_error("<NmpModPu> create listen io failed!"); return err; } nmp_net_set_heavy_io_load(self->listen_io); nmp_app_mod_set_name(am_self, "MOD-MDU"); nmp_mod_mds_register_msg_handler(self); return 0; }
/* * Create a event source object for connection. The object * will be added to "Event Context" for polling. */ __export HmWatch * hm_listen_watch_create(HmConnection *conn, HmWatchFuncs *funcs, gint size) { GSource *source; HmWatch *watch; G_ASSERT(conn != NULL && funcs != NULL && size >= sizeof(HmWatch)); source = g_source_new(&hm_watch_funcs, size); watch = (HmWatch*)source; watch->buffer = NULL; watch->lock = g_mutex_new(); watch->conn = conn; watch->funcs = funcs; watch->r_fd.fd = hm_connection_get_fd(conn); watch->r_fd.events = READ_COND; watch->r_fd.revents = 0; hm_watch_init_time(watch); watch->w_pending = 0; watch->killed = 0; watch->heavy_io_load = hm_connection_is_heavy(conn); watch->block_size = hm_connection_get_buffer_size(conn); hm_watch_set_callback(watch, hm_watch_listen_dispatch, NULL); g_source_add_poll(source, &watch->r_fd); g_atomic_int_add(&total_watch_count, 1); return watch; }
__export void hm_watch_attach(HmWatch *watch, GMainContext *context) { G_ASSERT(watch != NULL); g_source_attach((GSource*)watch, context); }
GReal GAnimTRSNode2D::Rotation(const GTimeValue TimePos, const GSpaceSystem Space, GTimeInterval& ValidInterval) const { GProperty *tmpProp = Property("transform"); if (!tmpProp) return 0; tmpProp = tmpProp->Property("rotation"); G_ASSERT(tmpProp); GTimeInterval tmpValid = G_FOREVER_TIMEINTERVAL; GKeyValue tmpValue; GError err = tmpProp->Value(tmpValue, tmpValid, TimePos, G_ABSOLUTE_VALUE); if (err != G_NO_ERROR) return 0; ValidInterval = tmpValid; // take care of father if (gFather && Space == G_WORLD_SPACE) { GReal retValue = tmpValue.RealValue(); retValue += gFather->Rotation(TimePos, G_WORLD_SPACE, tmpValid); ValidInterval &= tmpValid; return retValue; } return tmpValue.RealValue(); }
static void nmp_sysmsg_init(NmpSysMsg *self) { G_ASSERT(self != NULL); INIT_MSGID(self->msg_id); self->flags = FLG_SYSMSG_FORWARD; self->packet_layer.seq = 0; self->from_io = NULL; self->dst = BUSSLOT_POS_MAX; self->src = BUSSLOT_POS_MAX; self->orig = BUSSLOT_POS_MAX; self->priv = nmp_new0(NmpSysMsgPriv, 1); BUG_ON(!self->priv); /* glib says never */ self->user_data = NULL; self->user_size = 0; g_atomic_int_add(&total_sysmsg_count, 1); { //@{debug} static guint print_tag = 0; if (++print_tag % 1000 == 0) { nmp_print( "===== NOW TOTAL SYSMSG OJBECTS: %d =====", g_atomic_int_get(&total_sysmsg_count) ); } } }
gint nmp_mod_mds_new_mds(NmpModMds *self, NmpNetIO *io, const gchar *id, NmpID *conflict) { NmpGuestBase *mds; gint ret; G_ASSERT(self != NULL && io != NULL); mds = nmp_mods_guest_new(sizeof(NmpMds), id, nmp_mod_mds_destroy, self); if (G_UNLIKELY(!mds)) return -E_NOMEM; nmp_mod_mds_struct_init((NmpMds*)mds); nmp_mods_guest_attach_io(mds, io); ret = nmp_mods_container_add_guest(self->container, mds, conflict); if (G_UNLIKELY(ret)) { nmp_print( "<NmpModMds> mds:%s register failed, err:%d", id, ret ); } nmp_mods_guest_unref(mds); return ret; }