Esempio n. 1
0
File: test.cpp Progetto: nandai/slog
void StringTest::test03()
{
    SLOG(CLS_NAME, "test03");
    FixedString<10> str = "1234567890";

    try
    {
        str.copy("1234567890a");
        SASSERT("01", false);
    }
    catch (Exception e)
    {
        SMSG(slog::INFO, e.getMessage());
        SASSERT("01", true);
    }

    try
    {
        FixedString<10> str2 = "1234567890a";
        SASSERT("02", false);
    }
    catch (Exception e)
    {
        SMSG(slog::INFO, e.getMessage());
        SASSERT("02", true);
    }
}
Esempio n. 2
0
	void parse_materials(const char* json, Array<PhysicsConfigMaterial>& objects)
	{
		TempAllocator4096 ta;
		JsonObject object(ta);
		sjson::parse(json, object);

		auto begin = map::begin(object);
		auto end = map::end(object);

		for (; begin != end; ++begin)
		{
			const FixedString key = begin->pair.first;
			const char* value     = begin->pair.second;

			JsonObject material(ta);
			sjson::parse_object(value, material);

			PhysicsConfigMaterial mat;
			mat.name             = StringId32(key.data(), key.length());
			mat.static_friction  = sjson::parse_float(material["static_friction"]);
			mat.dynamic_friction = sjson::parse_float(material["dynamic_friction"]);
			mat.restitution      = sjson::parse_float(material["restitution"]);

			array::push_back(objects, mat);
		}
	}
Esempio n. 3
0
	static void parse_textures(const char* json, Array<TextureData>& textures, Array<char>& names, Array<char>& dynamic, CompileOptions& opts)
	{
		TempAllocator4096 ta;
		JsonObject object(ta);
		sjson::parse(json, object);

		auto begin = json_object::begin(object);
		auto end = json_object::end(object);

		for (; begin != end; ++begin)
		{
			const FixedString key = begin->pair.first;
			const char* value     = begin->pair.second;

			DynamicString texture(ta);
			sjson::parse_string(value, texture);
			RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_TEXTURE, texture.c_str(), opts);

			TextureHandle th;
			th.sampler_handle = 0;
			th.texture_handle = 0;

			const u32 sampler_name_offset = array::size(names);
			array::push(names, key.data(), key.length());
			array::push_back(names, '\0');

			TextureData td;
			td.sampler_name_offset = sampler_name_offset;
			td.id                  = sjson::parse_resource_id(value);
			td.data_offset         = reserve_dynamic_data(th, dynamic);

			array::push_back(textures, td);
		}
	}
Esempio n. 4
0
	void parse_actors(const char* json, Array<PhysicsConfigActor>& objects)
	{
		TempAllocator4096 ta;
		JsonObject object(ta);
		sjson::parse(json, object);

		auto begin = map::begin(object);
		auto end = map::end(object);

		for (; begin != end; ++begin)
		{
			const FixedString key = begin->pair.first;
			const char* value     = begin->pair.second;

			JsonObject actor(ta);
			sjson::parse_object(value, actor);

			PhysicsConfigActor pa2;
			pa2.name            = StringId32(key.data(), key.length());
			// pa2.linear_damping  = sjson::parse_float(actor["linear_damping"]);  // 0.0f;
			// pa2.angular_damping = sjson::parse_float(actor["angular_damping"]); // 0.05f;

			const bool has_dynamic         = map::has(actor, FixedString("dynamic"));
			const bool has_kinematic       = map::has(actor, FixedString("kinematic"));
			const bool has_disable_gravity = map::has(actor, FixedString("disable_gravity"));

			pa2.flags = 0;

			if (has_dynamic)
			{
				pa2.flags |= (sjson::parse_bool(actor["dynamic"])
					? 1
					: 0
					);
			}
			if (has_kinematic)
			{
				pa2.flags |= (sjson::parse_bool(actor["kinematic"])
					? PhysicsConfigActor::KINEMATIC
					: 0
					);
			}
			if (has_disable_gravity)
			{
				pa2.flags |= (sjson::parse_bool(actor["disable_gravity"])
					? PhysicsConfigActor::DISABLE_GRAVITY
					: 0
					);
			}

			array::push_back(objects, pa2);
		}
	}
Esempio n. 5
0
//--------------------------------------------------------------------------------------------------------
void CallbackFileChange( const char * szFileName )
{
	char buffer[ MAX_PATH ];
	GetCurrentDirectory( sizeof( buffer ), buffer );
	uint32_t dwSize = strlen( buffer );
	if ( 0 != strncmp( buffer, szFileName, dwSize ) )
		return;

	const char * szName = szFileName + dwSize + 1;

	FixedString s( szName );
	FixedString sExt = s.GetExt();
	strlwr(sExt.str());
	if ( sExt == ".dds" || sExt == ".tga" || sExt == ".bmp" )
	{
		r3dRenderer->ReloadTextureData( szName );
		return;
	}	

	if ( sExt == ".hls")
	{
		r3dRenderer->ReloadShaderByFileName(szName);
		return;
	}

	if ( sExt == ".sco")
	{
		ReloadMesh( szName );
		return;
	}

	if ( sExt == ".anm")
	{
		extern r3dAnimPool* g_CharactersAnimationsPool;
		g_CharactersAnimationsPool->Reload(szName);
		return;
	}

	if( g_pMaterialTypes->CheckNeedReload( szName ) )
	{
		if( !g_pMaterialTypes->Load() )
		{
			MessageBox( NULL, "Error reloading material types! Please, check your XML syntax!", "Error", MB_ICONEXCLAMATION );
		}
	}
}
Esempio n. 6
0
/*!
 * \brief   
 */
void SequenceLogFileManager::enumFileInfoList(const CoreString* dirName)
{
    if (mFileInfoArray.size() > 0)
        return;

    FixedString<MAX_PATH> path;
    FileFind find;
    find.setListener(this);

    path.format("%s%c%08d%c*.slog", dirName->getBuffer(), PATH_DELIMITER, mUserId, PATH_DELIMITER);
    find.exec(&path);

    path.format("%s%c%08d%c*.log",  dirName->getBuffer(), PATH_DELIMITER, mUserId, PATH_DELIMITER);
    find.exec(&path);

    mFileInfoArray.sort(CompareFileInfo());
}
Esempio n. 7
0
s32 SysDebugPrintf(const s8* strFormatting, ...)
{
	FixedString<1024> workBuffer;

	va_list ArgList;
	va_start(ArgList, strFormatting);
	s32 nRet = SysString::Vsprintf(workBuffer.Buffer(), workBuffer.Size(), strFormatting, ArgList);
	va_end(ArgList);

	#if defined(WIN32)
		
		OutputDebugString(workBuffer.ConstBuffer());
		return nRet;

	#else

		return printf(workBuffer.ConstBuffer());

	#endif
}
Esempio n. 8
0
	void parse_shapes(const char* json, Array<PhysicsConfigShape>& objects)
	{
		TempAllocator4096 ta;
		JsonObject object(ta);
		sjson::parse(json, object);

		auto begin = map::begin(object);
		auto end = map::end(object);

		for (; begin != end; ++begin)
		{
			const FixedString key = begin->pair.first;
			const char* value     = begin->pair.second;

			JsonObject shape(ta);
			sjson::parse_object(value, shape);

			PhysicsConfigShape ps2;
			ps2.name    = StringId32(key.data(), key.length());
			ps2.trigger = sjson::parse_bool(shape["trigger"]);

			array::push_back(objects, ps2);
		}
	}
TEST(FixedString, general) {
  const int kMax = 128;
  FixedString<kMax> fs = "123";
  EXPECT_TRUE(fs.capacity() == kMax);

  EXPECT_TRUE(fs == "123");
  EXPECT_TRUE(fs[0] == '1');
  EXPECT_TRUE(fs.front() == '1');
  EXPECT_TRUE(fs.back() == '3');
  EXPECT_TRUE(fs.size() == 3);

  fs += "4";
  EXPECT_TRUE(fs.size() == 4);
  EXPECT_TRUE(fs.capacity() == kMax);

  FixedString<kMax>::iterator it = fs.begin();
  EXPECT_TRUE(*it == '1');
}
Esempio n. 10
0
		void parse(const char* json)
		{
			TempAllocator4096 ta;
			JsonObject object(ta);
			sjson::parse(json, object);

			auto begin = map::begin(object);
			auto end = map::end(object);
			for (; begin != end; ++begin)
			{
				const FixedString key = begin->pair.first;
				const StringId32 id   = StringId32(key.data(), key.length());

				map::set(_filter_map, id, new_filter_mask());
			}

			begin = map::begin(object);
			end = map::end(object);
			for (; begin != end; ++begin)
			{
				const FixedString key = begin->pair.first;
				const char* value     = begin->pair.second;
				const StringId32 id   = StringId32(key.data(), key.length());

				TempAllocator4096 ta;
				JsonObject filter(ta);
				sjson::parse_object(value, filter);

				JsonArray collides_with(ta);
				sjson::parse_array(filter["collides_with"], collides_with);

				u32 mask = 0;
				for (u32 i = 0; i < array::size(collides_with); ++i)
				{
					const StringId32 fi = sjson::parse_string_id(collides_with[i]);
					mask |= filter_to_mask(fi);
				}

				// Build mask
				PhysicsCollisionFilter pcf;
				pcf.name = id;
				pcf.me   = filter_to_mask(id);
				pcf.mask = mask;

				array::push_back(_filters, pcf);
			}
		}
Esempio n. 11
0
	static void parse_uniforms(const char* json, Array<UniformData>& uniforms, Array<char>& names, Array<char>& dynamic, CompileOptions& opts)
	{
		TempAllocator4096 ta;
		JsonObject object(ta);
		sjson::parse(json, object);

		auto begin = json_object::begin(object);
		auto end = json_object::end(object);

		for (; begin != end; ++begin)
		{
			const FixedString key = begin->pair.first;
			const char* value     = begin->pair.second;

			UniformHandle uh;
			uh.uniform_handle = 0;

			JsonObject uniform(ta);
			sjson::parse_object(value, uniform);

			DynamicString type(ta);
			sjson::parse_string(uniform["type"], type);

			const UniformType::Enum ut = name_to_uniform_type(type.c_str());
			RESOURCE_COMPILER_ASSERT(ut != UniformType::COUNT
				, opts
				, "Unknown uniform type: '%s'"
				, type.c_str()
				);

			const u32 name_offset = array::size(names);
			array::push(names, key.data(), key.length());
			array::push_back(names, '\0');

			UniformData ud;
			ud.type        = ut;
			ud.name        = StringId32(key.data(), key.length());
			ud.name_offset = name_offset;
			ud.data_offset = reserve_dynamic_data(uh, dynamic);

			switch (ud.type)
			{
			case UniformType::FLOAT:
				reserve_dynamic_data(sjson::parse_float(uniform["value"]), dynamic);
				break;

			case UniformType::VECTOR2:
				reserve_dynamic_data(sjson::parse_vector2(uniform["value"]), dynamic);
				break;

			case UniformType::VECTOR3:
				reserve_dynamic_data(sjson::parse_vector3(uniform["value"]), dynamic);
				break;

			case UniformType::VECTOR4:
				reserve_dynamic_data(sjson::parse_vector4(uniform["value"]), dynamic);
				break;

			default:
				CE_FATAL("Unknown uniform type");
				break;
			}

			array::push_back(uniforms, ud);
		}
	}
Esempio n. 12
0
/*!
 *  \brief  メイン
 */
int main()
{
#if defined(_WINDOWS)
    SetConsoleTitleA("Sequence Log Print");

    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    WORD wAttributes;

    GetConsoleScreenBufferInfo(hStdout, &csbi);
#endif

    Socket::startup();
    Socket sock;

    try
    {
        sock.open(true, SOCK_DGRAM);
        sock.setReUseAddress(true);
        sock.bind(59108);
    }
    catch (Exception e)
    {
        int32_t errorNo = e.getErrorNo();

        if (errorNo == WSAEADDRINUSE)
            printf("port in use.\n");
        else
            printf("unknown error (0x%08X).\n", (unsigned int)errorNo);

        return 1;
    }

    printf("--- Sequence Log Print started. ---\n");

//  while (true)
    {
        while (true)
        {
            static const int32_t len = 768;
//          FixedString<1024> buffer;
            FixedString<len>  buffer;

            try
            {
//          sock.recv(&len);
            sock.recv(&buffer, len);

            switch (buffer[0])
            {
            case 'd':
#if defined(_WINDOWS)
                wAttributes = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
#else
                printf("\x1B[32;49;0m");
#endif
                break;

            case 'i':
#if defined(_WINDOWS)
                wAttributes = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
#else
                printf("\x1B[37;49;1m");
#endif
                break;

            case 'w':
#if defined(_WINDOWS)
                wAttributes = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
#else
                printf("\x1B[33;49;1m");
#endif
                break;

            case 'e':
#if defined(_WINDOWS)
                wAttributes = FOREGROUND_RED | FOREGROUND_INTENSITY;
#else
                printf("\x1B[31;49;1m");
#endif
                break;

            default:
#if defined(_WINDOWS)
                wAttributes = FOREGROUND_BLUE;
#else
#endif
                break;
            }
            }
            catch (Exception e)
            {
                printf("%s\n", e.getMessage());
//              break;
            }

#if defined(_WINDOWS)
            SetConsoleTextAttribute(hStdout, wAttributes);
#endif

            buffer.setLength(len);
            printf("%s", buffer.getBuffer() + 1);
        }

        printf("\n");
    }

#if defined(_WINDOWS)
    SetConsoleTextAttribute(hStdout, csbi.wAttributes);
#else
    printf("\x1B[39;49;0m");
#endif

    Socket::cleanup();
    return 0;
}