/*
 * Called from game/g_main.c/G_InitGame().
 * Initializes the variables and the bots for the game.
 */
void qv_initEnvironment(void) {	
	int i;
	int roundNum;
	char **botNames = malloc(sizeof(char*) * getSettings()->bots);
	char *botName;

	/* Check if testmode is on, if so go to testEnvironment */
	if (getSettings()->testmode) {
		initTestEnvironment();
		return;
	}

	roundNum = readRoundNum();
	switch (roundNum) {
		case 0:
			/* Com_Printf("\n\n^4  <-------> INITIALIZING QV ENVIRONMENT <------->\n"); */

			/*
			 * during initial round (0), completely random bots must be generated
			 * and added to bot database so genetic algorithm can start properly
			 * (bots generated here cannot yet be loaded ingame so round 0 just
			 * serves as setup)
			 */
			for(i = 0; i < getSettings()->bots; i++) {
				botNames[i] = generateBotName(roundNum + 1, QV_RANDOM_BOT_STR, (i+1));
			}
			generateRandomGenes(roundNum + 1, botNames);
			startNextRound(roundNum);
			
			for(i = 0; i < getSettings()->bots; i++) {
				free(botNames[i]);
			}			
			break;

		case 1:
			/* spawn bots generated in dummy setup round */
			for(i = 0; i < getSettings()->bots; i++) {
				botName = generateBotName(roundNum, QV_RANDOM_BOT_STR, (i+1));
				spawnBot(botName);
				free(botName);
			}
			break;

		default:
			/*
			 * child bots generated at end of previous round must be spawned
			 * here since Quake does not know about any new bots.txt aliases 
			 * until start of next round
			 */
			for(i = 0; i < getSettings()->bots; i++) {
				botName = generateBotName(roundNum, QV_CHILD_BOT_STR, (i+1));
				spawnBot(botName);
				free(botName);
			}
			break;
	}
	
	trap_SendConsoleCommand(EXEC_APPEND, "team spectator\n");
	trap_SendConsoleCommand(EXEC_APPEND, "bot_nochat 1\n");
	free(botNames);
	freeSettings();
}
Ejemplo n.º 2
0
namespace meshobjloader_test
{

int initTestEnvironment()
{
    BackTrace::autodump() ;
    return 0;
}
int s_autodump = initTestEnvironment() ;


class MeshObjLoader_test  : public ::testing::Test, public MeshObjLoader
{
public :

    /**
     * Constructor call for each test
     */
    void SetUp() override{}

    /**
     * Helper function to check mesh loading.
     * Compare basic values from a mesh with given results.
     */
    void loadTest(std::string filename, int pointNb, int edgeNb, int triangleNb,  int quadNb, int polygonNb,
                  int tetraNb, int hexaNb, int normalPerVertexNb, int normalListNb, int texCoordListNb, int materialNb)
    {
        SOFA_UNUSED(normalListNb);
        SOFA_UNUSED(texCoordListNb);
        SOFA_UNUSED(materialNb);

        this->setFilename(sofa::helper::system::DataRepository.getFile(filename));

        EXPECT_TRUE(this->load());
        EXPECT_EQ((size_t)pointNb, this->d_positions.getValue().size());
        EXPECT_EQ((size_t)edgeNb, this->d_edges.getValue().size());
        EXPECT_EQ((size_t)triangleNb, this->d_triangles.getValue().size());
        EXPECT_EQ((size_t)quadNb, this->d_quads.getValue().size());
        EXPECT_EQ((size_t)polygonNb, this->d_polygons.getValue().size());
        EXPECT_EQ((size_t)tetraNb, this->d_tetrahedra.getValue().size());
        EXPECT_EQ((size_t)hexaNb, this->d_hexahedra.getValue().size());
        EXPECT_EQ((size_t)normalPerVertexNb, this->d_normals.getValue().size());
    }

};

/** MeshObjLoader::load()
 * For a given meshes check that imported data are correct
 */
TEST_F(MeshObjLoader_test, LoadCall)
{
    //Check loader high level result
    EXPECT_FALSE(this->load());
    this->setFilename(sofa::helper::system::DataRepository.getFile("mesh/square.obj"));
    EXPECT_TRUE(this->load());

    //Use several meshes to test : edges, triangles, quads, normals, materials NUMBER
    loadTest("mesh/square.obj", 4, 4, 0,  0, 0, 0, 0, 0, 0, 0, 0);
    loadTest("mesh/dragon.obj", 1190, 0, 2564,  0, 0, 0, 0, 0, 0, 0, 0);
    loadTest("mesh/box.obj", 4, 0, 4,  0, 0, 0, 0, 4, 2, 0, 0);
    loadTest("mesh/cube.obj", 8, 0, 12,  0, 0, 0, 0, 8, 8, 0, 0);
    loadTest("mesh/caducee_base.obj", 3576, 0, 420,  3350, 0, 0, 0, 0, 0, 0, 8);
    loadTest("mesh/torus.obj", 800, 0, 1600,  0, 0, 0, 0, 0, 0, 861, 0);
}

} // namespace meshobjloader_test
Ejemplo n.º 3
0
namespace meshvtkloader_test
{

int initTestEnvironment()
{
    BackTrace::autodump() ;
    return 0;
}
int s_autodump = initTestEnvironment() ;


struct MeshVTKLoaderTest : public ::testing::Test,
                            public MeshVTKLoader
{
    using BaseVTKDataIO = component::loader::BaseVTKReader::BaseVTKDataIO;
    template<typename T>
    using VTKDataIO = component::loader::BaseVTKReader::VTKDataIO<T>;

    MeshVTKLoaderTest()
    {}

    void testLoad(std::string const& filename, unsigned nbPoints, unsigned nbEdges, unsigned nbTriangles, unsigned nbQuads, unsigned nbPolygons, unsigned nbTetrahedra, unsigned nbHexahedra)
    {
        setFilename(filename);
        EXPECT_TRUE(load());
        EXPECT_EQ(nbPoints, d_positions.getValue().size());
        EXPECT_EQ(nbEdges, d_edges.getValue().size());
        EXPECT_EQ(nbTriangles, d_triangles.getValue().size());
        EXPECT_EQ(nbQuads, d_quads.getValue().size());
        EXPECT_EQ(nbPolygons, d_polygons.getValue().size());
        EXPECT_EQ(nbTetrahedra, d_tetrahedra.getValue().size());
        EXPECT_EQ(nbHexahedra, d_hexahedra.getValue().size());
    }

};

TEST_F(MeshVTKLoaderTest, detectFileType)
{
    ASSERT_EQ(MeshVTKLoader::LEGACY, detectFileType(DataRepository.getFile("mesh/liver.vtk").c_str()));
    ASSERT_EQ(MeshVTKLoader::XML, detectFileType(DataRepository.getFile("mesh/Armadillo_Tetra_4406.vtu").c_str()));
}

TEST_F(MeshVTKLoaderTest, loadLegacy)
{
    testLoad(DataRepository.getFile("mesh/liver.vtk"), 5008, 0, 10000, 0, 0, 0, 0);
}

TEST_F(MeshVTKLoaderTest, loadXML)
{
    testLoad(DataRepository.getFile("mesh/Armadillo_Tetra_4406.vtu"), 1446, 0, 0, 0, 0, 4406, 0);
}

TEST_F(MeshVTKLoaderTest, loadLegacy_binary)
{
    using BaseData = core::objectmodel::BaseData;

    testLoad(DataRepository.getFile("mesh/vox8_binary.vtk"), 27, 0, 0, 0, 0, 0, 8);

    BaseData* cRamp1 = this->findData("cRamp1");
    EXPECT_TRUE(cRamp1 != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<float>>*>(cRamp1) != nullptr);

    BaseData* cRamp2 = this->findData("cRamp2");
    EXPECT_TRUE(cRamp2 != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<float>>*>(cRamp2) != nullptr);

    BaseData* cVects = this->findData("cVects");
    EXPECT_TRUE(cVects != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<defaulttype::Vec3f>>*>(cVects) != nullptr);

    BaseData* cv2 = this->findData("cv2");
    EXPECT_TRUE(cv2 != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<defaulttype::Vec3f>>*>(cv2) != nullptr);

    BaseData* mytest = this->findData("mytest");
    EXPECT_TRUE(mytest != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<float>>*>(mytest) != nullptr);

    BaseData* xRamp = this->findData("xRamp");
    EXPECT_TRUE(xRamp != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<float>>*>(xRamp) != nullptr);

    BaseData* yRamp = this->findData("yRamp");
    EXPECT_TRUE(yRamp != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<float>>*>(yRamp) != nullptr);

    BaseData* zRamp = this->findData("zRamp");
    EXPECT_TRUE(zRamp != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<float>>*>(zRamp) != nullptr);

    BaseData* outVect = this->findData("outVect");
    EXPECT_TRUE(outVect != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<defaulttype::Vec3f>>*>(outVect) != nullptr);

    BaseData* vect2 = this->findData("vect2");
    EXPECT_TRUE(vect2 != nullptr);
    EXPECT_TRUE(dynamic_cast<Data<helper::vector<defaulttype::Vec3f>>*>(vect2) != nullptr);
}

TEST_F(MeshVTKLoaderTest, loadInvalidFilenames)
{
    ExpectMessage errmsg(Message::Error) ;

    setFilename("");
    EXPECT_FALSE(load());

    setFilename("/home/test/thisisnotavalidpath");
    EXPECT_FALSE(load());

    setFilename(DataRepository.getFile("test.vtu"));
    EXPECT_FALSE(load());

    setFilename(DataRepository.getFile("test.vtk"));
    EXPECT_FALSE(load());
}

//TODO(dmarchal): Remove this tests until we can fix them.
#if 0
TEST_F(MeshVTKLoaderTest, loadBrokenVtkFile_OpenIssue)
{
    setFilename(DataRepository.getFile("mesh/liver_for_test_broken.vtk"));
    EXPECT_FALSE(load());
}

TEST_F(MeshVTKLoaderTest, loadBrokenVtuFile_OpenIssue)
{
    setFilename(DataRepository.getFile("mesh/Armadillo_Tetra_4406_for_test_broken.vtu"));
    EXPECT_FALSE(load());
}
#endif

}// namespace meshvtkloader_test