Skip to content
Permalink
Browse files

Turn the namespace V upside-down

  • Loading branch information...
satgo1546 committed Aug 5, 2017
1 parent e8e916d commit 34dfe83ed391bead14d870e385f229679c1378c1
@@ -61,7 +61,7 @@ namespace ASM76 {
private:
const char* original_prg;
const char* prg;
VVector<Tag> tags;
V::Vector<Tag> tags;
public:
Assembler(const char*);
void scan();
@@ -47,7 +47,7 @@ namespace ASM76 {
// ● 第二遍扫描(汇编)
//-------------------------------------------------------------------------
Program Assembler::assemble() {
VVector<uint8_t, false> instructs(120);
V::Vector<uint8_t, false> instructs(120);
while (prg && *prg) switch (*prg) {
case '#':
case '[':
@@ -16,7 +16,7 @@ namespace ASM76 { namespace ObjectCode {
const uint64_t magic = 0x36374d56e2a3efa3; // “obVM76” in GB2312
Program read_file(const char* filename) {
Program r;
VBinaryFileReader f(filename);
V::BinaryFileReader f(filename);
if (f.read_u64() != magic) {
printf("Error: magic is not correct\n");
r.size = 0;
@@ -33,7 +33,7 @@ namespace ASM76 { namespace ObjectCode {
return r;
}
bool write_file(const char* filename, Program program) {
VBinaryFileWriter f(filename);
V::BinaryFileWriter f(filename);
f.write_u64(magic);
f.write_u32(program.size);
for (size_t i = 0; i < program.size / sizeof(Instruct); i++) {
@@ -23,6 +23,4 @@ namespace V {
#include "VBinaryFileWriter.hpp"
}

// 自杀式命名空间
using namespace V;
#endif
@@ -6,7 +6,7 @@

#define ERROR_MESSAGE "error: cannot find beer"

class VBinaryFileReader {
class BinaryFileReader {
public:
//-------------------------------------------------------------------------
// ● 成员
@@ -16,13 +16,13 @@ class VBinaryFileReader {
// ● 构造
// 请自行检查f是否为NULL。
//-------------------------------------------------------------------------
VBinaryFileReader(const char* filename) {
BinaryFileReader(const char* filename) {
f = fopen(filename, "rb");
}
//-------------------------------------------------------------------------
// ● 析构
//-------------------------------------------------------------------------
~VBinaryFileReader() {
~BinaryFileReader() {
fclose(f);
}
//-------------------------------------------------------------------------
@@ -6,7 +6,7 @@

#define ERROR_MESSAGE "error: lorem ipsum"

class VBinaryFileWriter {
class BinaryFileWriter {
public:
//-------------------------------------------------------------------------
// ● 成员
@@ -15,13 +15,13 @@ class VBinaryFileWriter {
//-------------------------------------------------------------------------
// ● 构造
//-------------------------------------------------------------------------
VBinaryFileWriter(const char* filename) {
BinaryFileWriter(const char* filename) {
f = fopen(filename, "wb");
}
//-------------------------------------------------------------------------
// ● 析构
//-------------------------------------------------------------------------
~VBinaryFileWriter() {
~BinaryFileWriter() {
fclose(f);
}
//-------------------------------------------------------------------------
@@ -4,7 +4,7 @@
// 提供一些标准库里没有的数学函数。
//=============================================================================

namespace VMath {
namespace Math {
//-------------------------------------------------------------------------
// ● 常量
//-------------------------------------------------------------------------
@@ -4,7 +4,7 @@
// 环状队列数据结构模板类。
//=============================================================================

template <class T, size_t size> class VRingBuffer {
template <class T, size_t size> class RingBuffer {
private:
//-------------------------------------------------------------------------
// ● 一堆指针
@@ -19,14 +19,14 @@ template <class T, size_t size> class VRingBuffer {
//-------------------------------------------------------------------------
// ● 构造
//-------------------------------------------------------------------------
VRingBuffer() {
RingBuffer() {
buf_start = front = back = new T[size];
buf_end = buf_start + size;
}
//-------------------------------------------------------------------------
// ● 析构
//-------------------------------------------------------------------------
~VRingBuffer() {
~RingBuffer() {
delete[] buf_start;
}
//-------------------------------------------------------------------------
@@ -9,7 +9,7 @@ template <
// Sometimes we'd like to reserve the memory but destruct this class.
// In these case should cleanup be false.
bool cleanup = true
> class VVector {
> class Vector {
//-------------------------------------------------------------------------
// ● 实例变量
//-------------------------------------------------------------------------
@@ -22,14 +22,14 @@ template <
// ● 构造
// initial_capacity : number of objects of which to be reserved space
//-------------------------------------------------------------------------
VVector(size_t initial_capacity = 10) {
Vector(size_t initial_capacity = 10) {
capacity = initial_capacity;
start = end = (T*) malloc(capacity * sizeof(T));
}
//-------------------------------------------------------------------------
// ● 析构
//-------------------------------------------------------------------------
~VVector() {
~Vector() {
if (cleanup) free(start);
}
//-------------------------------------------------------------------------
@@ -57,9 +57,9 @@ namespace Audio {
FILE* f;
OggVorbis_File vf;
// AUDIO_VF_BUFFER_SIZE - 解码缓冲区的格数
// 由于VRingBuffer的实现,实际可用的格数比此数值少1。
// 由于V::RingBuffer的实现,实际可用的格数比此数值少1。
#define AUDIO_VF_BUFFER_SIZE ((size_t) 4096)
VRingBuffer<float, AUDIO_VF_BUFFER_SIZE> vf_buf;
V::RingBuffer<float, AUDIO_VF_BUFFER_SIZE> vf_buf;
bool eof;
bool loop;
int bitstream;
@@ -39,7 +39,7 @@ namespace Audio {
index_delta = -index_delta;
minus = !minus;
}
float value = VMath::sine_table[(size_t) (int) index];
float value = V::Math::sine_table[(size_t) (int) index];
if (minus) value = -value;
return value;
}
@@ -116,7 +116,7 @@ void init_engine(int w, int h, const char* title) {
Util::init();
log("initializing the engine");
srand(time(NULL));
log("The system is %s-endian.", is_little_endian() ? "little" : "big");
log("The system is %s-endian.", V::is_little_endian() ? "little" : "big");

init_vmde(w, h);
init_graphics(w, h, title);
@@ -34,9 +34,9 @@ namespace VM76 {
game_player.horizontal_angle -= 0.005 * (xpos - VMDE->width / 2.0);
game_player.vertical_angle -= 0.005 * (ypos - VMDE->height / 2.0);
game_player.vertical_angle = glm::clamp(
- VMath::PIf / 2 + 0.04f,
- V::Math::PIf / 2 + 0.04f,
game_player.vertical_angle,
VMath::PIf / 2
V::Math::PIf / 2
);
glfwSetCursorPos(window, VMDE->width / 2.0, VMDE->height / 2.0);
glm::vec3 direction = glm::vec3(
@@ -45,9 +45,9 @@ namespace VM76 {
cos(game_player.vertical_angle) * cos(game_player.horizontal_angle)
);
glm::vec3 right = glm::vec3(
sin(game_player.horizontal_angle - VMath::PIf / 2.0f),
sin(game_player.horizontal_angle - V::Math::PIf / 2.0f),
0,
cos(game_player.horizontal_angle - VMath::PIf / 2.0f)
cos(game_player.horizontal_angle - V::Math::PIf / 2.0f)
);
glm::vec3 up = glm::cross(right, direction);
glm::vec3 cam_pos = game_player.wpos + glm::vec3(0.0, 1.68, 0.0);
@@ -29,7 +29,7 @@ namespace VM76 {

bool DataMap::read_map() {
log("Reading map");
VBinaryFileReader* fr = new VBinaryFileReader("map.dat");
V::BinaryFileReader* fr = new V::BinaryFileReader("map.dat");
if (!fr->f) return false;

int map_version = fr->read_i32();
@@ -50,7 +50,7 @@ namespace VM76 {
}

void DataMap::save_map() {
VBinaryFileWriter* fw = new VBinaryFileWriter("map.dat");
V::BinaryFileWriter* fw = new V::BinaryFileWriter("map.dat");
// 版本号
fw->write_i32(100);
// 文件头标识
@@ -78,11 +78,11 @@ namespace VM76 {
);
block_display = glm::scale(block_display, glm::vec3(0.1f));
block_display = glm::rotate(block_display,
VMath::PIf / 4.0f,
V::Math::PIf / 4.0f,
glm::vec3(1.0, 0.0, 0.0)
);
block_display = glm::rotate(block_display,
VMath::PIf / 4.0f,
V::Math::PIf / 4.0f,
glm::vec3(0.0, 1.0, 0.0)
);

@@ -275,7 +275,7 @@ namespace VM76 {

deferred_lighting.use();
deferred_lighting.set_texture("normal", postBuffer->texture_buffer[BufferNormal], 1);
glm::vec3 sunVec = glm::mat3(view) * glm::vec3(cos(VMath::PI * 0.25), sin(VMath::PI * 0.25), sin(VMath::PI * 0.25) * 0.3f);
glm::vec3 sunVec = glm::mat3(view) * glm::vec3(cos(V::Math::PI * 0.25), sin(V::Math::PI * 0.25), sin(V::Math::PI * 0.25) * 0.3f);
deferred_lighting.set_vec3("sunVec", sunVec);
PostProcessingManager::Blit2D();

0 comments on commit 34dfe83

Please sign in to comment.
You can’t perform that action at this time.