//waveデータをサウンドバッファにコピー bool CSound::WriteDataToBuffer(IDirectSoundBuffer** buffer, void* data, DWORD dwOffset, DWORD dwWriteSize) { //EnterCriticalSection(&m_csWriteBuffer); void* pmem[2]; DWORD alloc_size[2]; if(NULL == data || m_pSecondaryBuffer == NULL) return false; if(DSERR_BUFFERLOST == (*buffer)->Lock(dwOffset, dwWriteSize, &pmem[0], &alloc_size[0], &pmem[1], &alloc_size[1], 0)){//サウンドバッファをロック (*buffer)->Restore(); if(DS_OK != (*buffer)->Lock(dwOffset, dwWriteSize, &pmem[0], &alloc_size[0], &pmem[1], &alloc_size[1], 0)) return false; } //読み込んだサイズ分コピー if(pmem[0]){ CORE_ASSERT(dwWriteSize==alloc_size[0], ""); copyMem(pmem[0], data, alloc_size[0]); }else if(pmem[1]){ CORE_ASSERT(dwWriteSize==alloc_size[1], ""); copyMem(pmem[1], data, alloc_size[1]); }else{ CORE_ASSERT(0, "sound memory allocation error"); } (*buffer)->Unlock(pmem[0], alloc_size[0], pmem[1], alloc_size[1]); //バッファをアンロック //LeaveCriticalSection(&m_csWriteBuffer); return true; }
void checkConsistency( const TriangleMesh& mesh ) { #ifdef CORE_DEBUG std::vector<bool> visited( mesh.m_vertices.size(), false ); for ( uint t = 0 ; t < mesh.m_triangles.size(); ++t ) { const Triangle& tri = mesh.m_triangles[t]; for ( uint i = 0; i < 3; ++i ) { std::string errStr; StringUtils::stringPrintf( errStr, "Vertex %d is in triangle %d (#%d) is out of bounds", tri[i], t, i ); CORE_ASSERT( uint( tri[i] ) < mesh.m_vertices.size(), errStr.c_str() ); visited[tri[i]] = true; } } for ( uint v = 0; v < visited.size(); ++v ) { std::string errStr; StringUtils::stringPrintf( errStr, "Vertex %d does not belong to any triangle", v ); CORE_ASSERT( visited[v], errStr.c_str() ); } // Normals are optional but if they are present then every vertex should have one. CORE_ASSERT( mesh.m_normals.size() == 0 || mesh.m_normals.size() == mesh.m_vertices.size(), "Inconsistent number of normals" ); #endif }
void Engine::Entity::setProperty(const EditableProperty& prop) { switch (prop.getType()) { case EditableProperty::POSITION: { CORE_ASSERT(prop.getName() == "Position", "Wrong property"); std::lock_guard<std::mutex> lock(m_transformMutex); m_transform.translation() = prop.asPosition(); break; } case EditableProperty::ROTATION: { CORE_ASSERT(prop.getName() == "Rotation", "Wrong property"); std::lock_guard<std::mutex> lock(m_transformMutex); m_transform.linear() = prop.asRotation().toRotationMatrix(); break; } default: CORE_ASSERT(false, "Wrong property"); } }
bool csp::OpLua::CallLua( lua::LuaStack& stack, const char* functionName, int numArgs, int numRets ) { CORE_ASSERT( m_self != lua::LUA_NO_REF ); stack.PushRegistryReferenced( m_self ); lua::LuaStackValue top = stack.GetTopValue(); CORE_ASSERT( top.IsTable() ); stack.GetField( top, functionName ); if ( !stack.GetTopValue().IsFunction() ) { stack.Pop( numArgs + 2 ); return false; } // stack at this point: arg1, arg2, argN, self, function stack.Insert( -numArgs-2 ); stack.Insert( -numArgs-1 ); // stack at this point: function, self, arg1, arg2, argN lua::LuaState luaState( stack.InternalState() ); lua::Return::Enum result = luaState.Call( 1+numArgs, numRets ); return result == lua::Return::OK; }
csp::WorkResult::Enum csp::Process::StartEvaluation( Host& host, int numArgs ) { CORE_ASSERT( m_operation == NULL ); CORE_ASSERT( LuaThread().Status() == lua::Return::OK ); CORE_ASSERT( LuaThread().GetStack()[-numArgs-1].IsFunction() ); return Evaluate( host, numArgs ); }
void csp::OpAlt::CloseChannel( csp::Host & host, Channel& channel ) { AltCase* pCaseClosed = FindCaseForChannel( channel ); CORE_ASSERT( pCaseClosed ); CORE_ASSERT( pCaseClosed->m_pChannel != NULL ); CloseCase( host.LuaState().GetStack(), *pCaseClosed ); channel.ResetAttachmentIn( *this ); }
void link_unsafe( Link& link ) { CORE_ASSERT(link.nextp == nullptr); CORE_ASSERT(!unlink_unsafe(link)); link.nextp = headp; headp = &link; }
void System::unregisterComponent( const Entity* ent, Component* component ) { CORE_ASSERT( component->getEntity() == ent, "Component does not belong to entity" ); const auto& pos = std::find_if(m_components.begin(), m_components.end(), [component](const auto& pair) { return pair.second == component; }); CORE_ASSERT( pos != m_components.end(), "Component is not registered." ); CORE_ASSERT( pos->first == ent, "Component belongs to a different entity" ); m_components.erase( pos ); }
void BaseGameManager::render() { CORE_ASSERT(m_pCameraFollowingSystem != nullptr); CORE_ASSERT(m_pRenderSystem != nullptr); m_pCameraFollowingSystem->process(); m_pRenderSystem->process(); m_pAnimationSystem->process(); // Draw debug data if(m_pPhysicsWorld) m_pPhysicsWorld->DrawDebugData(); }
void EntityManager::removeEntity( Core::Index idx ) { CORE_ASSERT( idx != Core::Index::INVALID_IDX() && m_entities.contain( idx ), "Trying to remove an entity that has not been added to the manager." ); auto ent = m_entities[idx]; std::string name = ent->getName(); CORE_ASSERT( ent.unique(), "Non-unique entity about to be removed." ); ent.reset(); m_entities.remove( idx ); m_entitiesName.erase( name ); }
T& PushBack(const T& item) { CORE_ASSERT( readonly == false ); if ( moffset >= mmaxsize ) { if ( !mmaxsize ) { mdata = new T[4]; mmaxsize = 4; moffset = 0; } else { int offset = moffset; int size = mmaxsize * 2; SetSize(size,true); moffset = offset; } } T& ref = mdata[moffset++]; ref = item; return ref; }
void csp::OpAlt::SelectTimeProcessToTrigger( Host& host ) { CORE_ASSERT( m_pCaseTriggered == NULL ); CspTime_t time = host.Time(); for( int i = 0; i < m_numCases; ++i ) { AltCase& altCase = m_cases[ i ]; if( m_pNilCase == &altCase ) continue; if( altCase.m_pChannel == NULL && altCase.m_time <= time ) { if( m_pCaseTriggered ) { if( altCase.m_time < m_pCaseTriggered->m_time ) m_pCaseTriggered = &altCase; } else m_pCaseTriggered = &altCase; } } if( m_pCaseTriggered ) { m_argumentsMoved = true; DetachChannels(); host.PushEvalStep( ThisProcess() ); } }
void BaseGameManager::update(float delta) { CORE_ASSERT(m_pWorld != nullptr); m_pWorld->loopStart(); m_pWorld->setDelta(delta); // Step physics world if(m_pPhysicsWorld) // If physics world exists, so does the physics system { // Use recommended velocity and position intervals according to Box2D manual // See: http://www.box2d.org/manual.html // // Actually, im gonna reduce velocity iterations a little for visible performance // increases m_pPhysicsWorld->Step(delta, 4, 2); m_pPhysicsSystem->process(); } // Update script system if(m_pScriptSystem) { m_pScriptSystem->process(); } }
void FancyMeshComponent::handleMeshLoading( const FancyComponentData& data ) { CORE_ASSERT( data.meshes.size() == 1, "One mesh per component / object." ); // FIXME(Charly): Change data meshes array to just one mesh Ra::Engine::RenderObject* renderObject = new Ra::Engine::RenderObject( data.name, this ); renderObject->setVisible( true ); for ( uint i = 0; i < data.meshes.size(); ++i ) { FancyMeshData meshData = data.meshes[i]; std::stringstream ss; ss << data.name << "_mesh_" << i; std::string meshName = ss.str(); Ra::Engine::Mesh* mesh = new Ra::Engine::Mesh( meshName ); mesh->loadGeometry( meshData.positions, meshData.indices ); mesh->addData( Ra::Engine::Mesh::VERTEX_NORMAL, meshData.normals ); mesh->addData( Ra::Engine::Mesh::VERTEX_TANGENT, meshData.tangents ); mesh->addData( Ra::Engine::Mesh::VERTEX_BITANGENT, meshData.bitangents ); mesh->addData( Ra::Engine::Mesh::VERTEX_TEXCOORD, meshData.texcoords ); renderObject->setMesh( mesh ); } renderObject->setRenderTechnique( data.renderTechnique ); m_renderObject = m_renderObjectManager->addRenderObject( renderObject ); }
void csp::Process::DeleteOperation( Host& host ) { CORE_ASSERT( m_operation ); m_operation->DebugCheck( host ); SwitchCurrentOperation( NULL ); }
void SetSize(int size, bool preserve = false) { CORE_ASSERT( readonly == false ); if ( size == mmaxsize ) { moffset = size; return; } T* array = 0; if ( size ) { array = new T[size]; if ( mdata && preserve ) { int size0 = GetSize(); int count = (size0 > size) ? size : size0; for ( int i=0; i<count; ++i ) array[i] = mdata[i]; } } delete[] mdata; mdata = array; mmaxsize = size; moffset = size; }
csp::WorkResult::Enum csp::OpTestSuite_RunAll::Evaluate( Host& host ) { if( m_pCurrentClosure ) { if( m_pCurrentClosure->process.IsRunning() ) return WorkResult::YIELD; else { if( m_pCurrentClosure->refKey != lua::LUA_NO_REF ) UnrefClosure( m_pCurrentClosure ); delete m_pCurrentClosure; m_pCurrentClosure = NULL; } } if( m_pCurrentClosure == NULL && m_pClosuresHead ) { TestClosure* pClosure = ListPopFromHead( m_pClosuresHead, m_pClosuresTail ); CORE_ASSERT( pClosure ); lua::Print( "Running test %s.%s...\n", pClosure->suiteName, pClosure->functionName ); m_pCurrentClosure = pClosure; pClosure->process.StartEvaluation( host, 0 ); } return IsFinished(); }
bool csp::OpAlt::SelectChannelProcessToTrigger( Host& host ) { CORE_ASSERT( m_pCaseTriggered == NULL ); bool allCasesClosed = true; for( int i = 0; i < m_numCases; ++i ) { AltCase& altCase = m_cases[ i ]; if( m_pNilCase == &altCase ) { m_pCaseTriggered = m_pNilCase; allCasesClosed = false; m_argumentsMoved = true; DetachChannels(); host.PushEvalStep( ThisProcess() ); break; } Channel* pChannel = altCase.m_pChannel; if( pChannel || altCase.m_time >= 0.0f ) allCasesClosed = false; if( pChannel && pChannel->OutAttached() ) { ChannelAttachmentOut_i& out = pChannel->OutAttachment(); out.Communicate( host, ThisProcess() ); break; } } return allCasesClosed; }
int Animation::getKeyFrameIndex(float stateTime) const { CORE_ASSERT(stateTime >= 0.f); int numKeyFrames = m_keyFrames.size(); if(numKeyFrames == 1) return 0; // Get the current frame number int frameNumber = (unsigned int)(stateTime / m_frameDuration); switch(m_kPlayMode) { case NORMAL: // If all frames are played, only use last frame frameNumber = glm::min(numKeyFrames - 1, frameNumber); break; case LOOP: frameNumber %= numKeyFrames; break; case LOOP_RANDOM: frameNumber = rand() % numKeyFrames; break; case REVERSED: frameNumber = glm::max(numKeyFrames - frameNumber - 1, 0); break; case LOOP_REVERSED: frameNumber %= numKeyFrames; frameNumber = numKeyFrames - frameNumber - 1; break; }; return frameNumber; }
void TrimArray() { CORE_ASSERT( readonly == false ); int size = GetSize(); SetSize(size,true); }
void Engine::Texture::updateData( void* data ) { GL_ASSERT(glBindTexture(target, m_textureId)); switch (target) { case GL_TEXTURE_1D: { GL_ASSERT(glTexImage1D(target, 0, internalFormat, m_width, 0, m_format, dataType, data)); } case GL_TEXTURE_2D: { GL_ASSERT(glTexImage2D(target, 0, internalFormat, m_width, m_height, 0, m_format, dataType, data)); } break; case GL_TEXTURE_3D: { GL_ASSERT(glTexImage3D(target, 0, internalFormat, m_width, m_height, m_depth, 0, m_format, dataType, data)); } break; default: { CORE_ASSERT( 0, "Dafuck ?" ); } break; } }
void RadiumEngine::registerSystem( const std::string& name, System* system ) { CORE_ASSERT( m_systems.find( name ) == m_systems.end(), "Same system added multiple times." ); m_systems[name] = std::shared_ptr<System> ( system ); }
Animation::Animation(float frameDuration, const KeyFrames& keyFrames, PlayMode playMode) : m_keyFrames(keyFrames) , m_kPlayMode(playMode) , m_frameDuration(frameDuration) { CORE_ASSERT(!keyFrames.empty()); m_animationDuration = keyFrames.size() * m_frameDuration; }
void csp::OpAlt::MoveChannelArguments( Channel& channel, ChannelArgument* arguments, int numArguments ) { CORE_ASSERT( m_arguments == NULL ); CORE_ASSERT( m_numArguments == CSP_NO_ARGS ); CORE_ASSERT( numArguments != CSP_NO_ARGS ); AltCase* pCaseTriggered = FindCaseForChannel( channel ); CORE_ASSERT( pCaseTriggered ); CORE_ASSERT( m_pCaseTriggered == NULL ); m_pCaseTriggered = pCaseTriggered; m_arguments = arguments; m_numArguments = numArguments; m_argumentsMoved = true; DetachChannels(); }
void Engine::Entity::removeComponent( const std::string& name ) { std::string err; Core::StringUtils::stringPrintf( err, "The component \"%s\" is not part of the entity \"%s\"", name.c_str(), m_name.c_str() ); CORE_ASSERT( m_components.find( name ) != m_components.end(), err.c_str() ); m_components.erase( name ); }
void GameManager::update(float delta) { CORE_ASSERT(m_pPlayerInputSystem != nullptr); // Super BaseGameManager::update(delta); // Update input m_pPlayerInputSystem->process(); }
void System::registerComponent( const Entity* ent, Component* component ) { // Perform checks on debug #if defined(DEBUG) CORE_ASSERT( component->getEntity() == ent, "Component does not belong to entity" ); for (const auto& pair : m_components) { CORE_ASSERT(pair.second != component, "Component already registered"); if (pair.first == ent) { CORE_ASSERT(pair.second->getName() != component->getName(), "A component with the same name is already associated with this entity"); } } #endif // DEBUG m_components.push_back({ ent, component }); component->setSystem( this ); }
Animation::Animation(float frameDuration, const KeyFrames& keyFrames) : m_keyFrames(keyFrames) , m_kPlayMode(NORMAL) , m_frameDuration(frameDuration) { // Dis-allow empty keyFrames CORE_ASSERT(!keyFrames.empty()); // Get complete animation time through the number of regions and time for each frame m_animationDuration = keyFrames.size() * m_frameDuration; }
void link_tail_unsafe( Link& link ) { Link* curp = headp; CORE_ASSERT(link.nextp == nullptr); CORE_ASSERT(!unlink_unsafe(link)); if (is_empty_unsafe()) { headp = &link; } else { while (curp->nextp != nullptr) { curp = curp->nextp; } curp->nextp = &link; } }
void Engine::Entity::addComponent( Engine::Component* component ) { std::string name = component->getName(); std::string err; Core::StringUtils::stringPrintf( err, "Component \"%s\" has already been added to the entity.", name.c_str() ); CORE_ASSERT( m_components.find( name ) == m_components.end(), err.c_str() ); m_components.insert( ComponentByName( name, component ) ); component->setEntity( this ); }