Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Detegr/pwskoag
base: 173a364278
...
head fork: Detegr/pwskoag
compare: 01dbfc773a
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -28,3 +28,4 @@ linux/
client
glm/
server
+*.pyc
View
80 .ycm_extra_conf.py
@@ -0,0 +1,80 @@
+import os
+import ycm_core
+from clang_helpers import PrepareClangFlags
+
+# Set this to the absolute path to the folder (NOT the file!) containing the
+# compile_commands.json file to use that instead of 'flags'. See here for
+# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
+# Most projects will NOT need to set this to anything; you can just change the
+# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
+compilation_database_folder = ''
+
+# These are the compilation flags that will be used in case there's no
+# compilation database set.
+flags = ["-Wall", "-Wextra", "-Werror", "-Wno-comment", "-std=c++0x", '-DUSE_CLANG_COMPLETER', '-x', 'c++', "-I", "."]
+
+if compilation_database_folder:
+ database = ycm_core.CompilationDatabase( compilation_database_folder )
+else:
+ database = None
+
+
+def DirectoryOfThisScript():
+ return os.path.dirname( os.path.abspath( __file__ ) )
+
+
+def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
+ if not working_directory:
+ return flags
+ new_flags = []
+ make_next_absolute = False
+ path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
+ for flag in flags:
+ new_flag = flag
+
+ if make_next_absolute:
+ make_next_absolute = False
+ if not flag.startswith( '/' ):
+ new_flag = os.path.join( working_directory, flag )
+
+ for path_flag in path_flags:
+ if flag == path_flag:
+ make_next_absolute = True
+ break
+
+ if flag.startswith( path_flag ):
+ path = flag[ len( path_flag ): ]
+ new_flag = path_flag + os.path.join( working_directory, path )
+ break
+
+ if new_flag:
+ new_flags.append( new_flag )
+ return new_flags
+
+
+def FlagsForFile( filename ):
+ if database:
+ # Bear in mind that compilation_info.compiler_flags_ does NOT return a
+ # python list, but a "list-like" StringVec object
+ compilation_info = database.GetCompilationInfoForFile( filename )
+ final_flags = PrepareClangFlags(
+ MakeRelativePathsInFlagsAbsolute(
+ compilation_info.compiler_flags_,
+ compilation_info.compiler_working_dir_ ),
+ filename )
+
+ # NOTE: This is just for YouCompleteMe; it's highly likely that your project
+ # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
+ # ycm_extra_conf IF YOU'RE NOT 100% YOU NEED IT.
+ try:
+ final_flags.remove( '-stdlib=libc++' )
+ except ValueError:
+ pass
+ else:
+ relative_to = DirectoryOfThisScript()
+ final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
+
+ return {
+ 'flags': final_flags,
+ 'do_cache': True
+ }
View
26 Makefile
@@ -1,13 +1,33 @@
-CC=g++ -Os -Wall -Wextra -Werror -Wno-comment -std=c++0x
+CC=g++ -g3 -Wall -Wextra -Werror -Wno-comment -std=c++0x
CFLAGS=-I/usr/local/include/GL -I/usr/local/include -L /usr/local/lib -L dtglib/
SERVERCFLAGS=-I/usr/local/include -L /usr/local/lib -Ldtglib/
SERVERLIBS=-ldtglib -lBox2D -lpthread
LIBS=-ldtglib -lGL -lGLU -lglfw -lXrandr -lBox2D -ldl -lpthread
OSXLIBS=-framework OpenGL -framework Cocoa -lglfw -lBox2D -ldtglib
-SOURCES=singleton.cpp renderer.cpp inputhandler.cpp shadermanager.cpp filereader.cpp modelmanager.cpp entity.cpp model.cpp gfxtimer.cpp timer.cpp
+SOURCES=singleton.cpp \
+ renderer.cpp \
+ inputhandler.cpp \
+ shadermanager.cpp \
+ filereader.cpp \
+ modelmanager.cpp \
+ entity.cpp \
+ model.cpp \
+ gfxtimer.cpp \
+ timer.cpp \
+ packetparser.cpp
+
MAIN=client.cpp
SERVERMAIN=server.cpp
-SERVERSOURCES=serversingleton.cpp filereader.cpp modelmanager.cpp model.cpp physicsmanager.cpp physicalentity.cpp timer.cpp ConnectionManager.cpp bullet.cpp contactlistener.cpp
+SERVERSOURCES= serversingleton.cpp \
+ filereader.cpp \
+ modelmanager.cpp \
+ model.cpp \
+ physicsmanager.cpp \
+ physicalentity.cpp \
+ timer.cpp \
+ ConnectionManager.cpp \
+ bullet.cpp \
+ contactlistener.cpp
SERVERHEADERS=$(SERVERSOURCES:.cpp=.h)
SERVEROBJECTS=$(SERVERSOURCES:.cpp=.o)
HEADERS=$(SOURCES:.cpp=.h)
View
9 entity.cpp
@@ -1,8 +1,8 @@
#include "singleton.h"
#include "entity.h"
-C_GfxEntity::C_GfxEntity() : m_Id(0), m_Model(), m_Scale(1.0f), m_ModelMatrix(glm::mat4(1.0f)) {}
-C_GfxEntity::C_GfxEntity(unsigned short id, const C_Model& m, float scale) : m_Id(id), m_Model(m), m_Scale(scale), m_ModelMatrix(glm::mat4(1.0f))
+C_GfxEntity::C_GfxEntity() : m_Id(0), m_IsPlayer(false), m_Model(), m_Scale(1.0f), m_ModelMatrix(glm::mat4(1.0f)) {}
+C_GfxEntity::C_GfxEntity(unsigned short id, const C_Model& m, float scale) : m_Id(id), m_IsPlayer(false), m_Model(m), m_Scale(scale), m_ModelMatrix(glm::mat4(1.0f))
{
M_Scale(scale);
glGenBuffers(1, &m_Vbo);
@@ -32,13 +32,11 @@ void C_GfxEntity::M_SetPosition(float x, float y)
m_Ex.M_Add(x);
m_Ey.M_Add(y);
m_TranslationMatrix = glm::translate(glm::mat4(1.0), glm::vec3(x/m_Scale,y/m_Scale,0.0f));
- //m_Pos.x=x*m_Scale;
- //m_Pos.y=y*m_Scale;
}
const C_Vec2 C_GfxEntity::GetPosition() const
{
- return C_Vec2(0,0);//m_Pos.x/m_Scale, m_Pos.y/m_Scale);
+ return C_Vec2(m_TranslationMatrix[3][0]*m_Scale, m_TranslationMatrix[3][1]*m_Scale);
}
void C_GfxEntity::M_ExtrapolatePosition(double dt)
@@ -48,7 +46,6 @@ void C_GfxEntity::M_ExtrapolatePosition(double dt)
float xxx = m_Ex.M_Current() + ((xx - m_Ex.M_Current()) * (dt/0.04));
float yyy = m_Ey.M_Current() + ((yy - m_Ey.M_Current()) * (dt/0.04));
m_TranslationMatrix = glm::translate(glm::mat4(1.0), glm::vec3(xxx/m_Scale,yyy/m_Scale,0.0f));
- //m_Pos.x=xxx*m_Scale; m_Pos.y=yyy*m_Scale;
}
void C_GfxEntity::M_Scale(float amount)
View
4 entity.h
@@ -2,6 +2,7 @@
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
+#include "glm/gtc/matrix_access.hpp"
#include "model.h"
#include "vec2.h"
#include "ringbuffer.h"
@@ -10,6 +11,7 @@ class C_GfxEntity
{
private:
unsigned short m_Id;
+ bool m_IsPlayer;
C_Extrapolator<float> m_Ex;
C_Extrapolator<float> m_Ey;
//C_Vec2 m_Pos;
@@ -41,4 +43,6 @@ class C_GfxEntity
const glm::mat4& M_ModelMatrix();
void M_Draw() const;
unsigned int M_Id() const { return m_Id; }
+ bool IsPlayer() const { return m_IsPlayer; }
+ void SetPlayer(bool b) { m_IsPlayer=b; }
};
View
1  networkenum.h
@@ -6,6 +6,7 @@ struct NET
{
Connect,
Disconnect,
+ PlayerId,
ModelBegin,
ModelIndex,
ModelDimensions,
View
103 packetparser.cpp
@@ -0,0 +1,103 @@
+#include "packetparser.h"
+
+#include "singleton.h"
+#include "model.h"
+#include "networkenum.h"
+#include <assert.h>
+#include <vector>
+
+void C_PacketParser::M_Parse(C_Packet& p)
+{
+ unsigned char header;
+ p >> header;
+ switch(header)
+ {
+ case NET::ModelBegin:
+ {
+ M_Model(p);
+ return;
+ }
+ case NET::EntityBegin:
+ {
+ M_GfxEntity(p, false);
+ return;
+ }
+ case NET::FullEntityBegin:
+ {
+ M_GfxEntity(p, true);
+ return;
+ }
+ case NET::EntityDeleted:
+ {
+ M_EntityDeleted(p);
+ return;
+ }
+ case NET::PlayerId:
+ {
+ unsigned short id;
+ p >> id;
+ C_Singleton::M_Renderer()->M_GetEntity(id)->SetPlayer(true);
+ return;
+ }
+ }
+ std::cout << "UNKNOWN HEADER: " << (int)header << std::endl;
+ assert(false);
+ return;
+}
+
+void C_PacketParser::M_EntityDeleted(C_Packet& p)
+{
+ unsigned short id;
+ p >> id;
+ C_Renderer* r=C_Singleton::M_Renderer();
+ r->M_DeleteEntity(r->M_GetEntity(id));
+}
+
+void C_PacketParser::M_GfxEntity(C_Packet& p, bool full)
+{
+ std::string name;
+ float scale,x,y,angle;
+ scale=x=y=angle=0.0f;
+ unsigned short id=65535;
+ if(full) p >> id >> name >> scale >> x >> y >> angle;
+ else p >> id >> x >> y >> angle;
+
+ C_Renderer* r=C_Singleton::M_Renderer();
+ C_GfxEntity* e=r->M_GetEntity(id);
+ if(e)
+ {
+ e->M_SetPosition(x,y);
+ e->M_SetRotation(angle);
+ }
+ else if(full)
+ {
+ std::cout << "Creating entity with id: " << id << std::endl;
+ C_GfxEntity* e=C_GfxEntity::M_Create(id, C_Singleton::M_ModelManager()->M_Get(name), scale);
+ e->M_SetPosition(x,y);
+ e->M_SetRotation(angle);
+ }
+}
+
+void C_PacketParser::M_Model(C_Packet& p)
+{
+ unsigned char header;
+
+ std::string name;
+ p >> name;
+
+ std::vector<float> verts;
+ p >> header;
+ while(header == NET::ModelIndex)
+ {
+ float f;
+ p >> f;
+ verts.push_back(f);
+ p >> header;
+ }
+ assert(header == NET::ModelDimensions);
+ float w,h;
+ p >> w;
+ p >> h;
+
+ C_Singleton::M_ModelManager()->M_Create(name, verts, w, h);
+}
View
94 packetparser.h
@@ -1,12 +1,6 @@
#pragma once
-#include "singleton.h"
-#include "model.h"
-#include "networkenum.h"
-#include <assert.h>
-#include <vector>
#include "dtglib/Packet.h"
-
using namespace dtglib;
class C_DummyParse {};
@@ -18,91 +12,3 @@ struct C_PacketParser
static void M_EntityDeleted(C_Packet& p);
static void M_Model(C_Packet& p);
};
-
-void C_PacketParser::M_Parse(C_Packet& p)
-{
- unsigned char header;
- p >> header;
- switch(header)
- {
- case NET::ModelBegin:
- {
- M_Model(p);
- return;
- }
- case NET::EntityBegin:
- {
- M_GfxEntity(p, false);
- return;
- }
- case NET::FullEntityBegin:
- {
- M_GfxEntity(p, true);
- return;
- }
- case NET::EntityDeleted:
- {
- M_EntityDeleted(p);
- return;
- }
- }
- std::cout << "UNKNOWN HEADER: " << (int)header << std::endl;
- assert(false);
- return;
-}
-
-void C_PacketParser::M_EntityDeleted(C_Packet& p)
-{
- unsigned short id;
- p >> id;
- C_Renderer* r=C_Singleton::M_Renderer();
- r->M_DeleteEntity(r->M_GetEntity(id));
-}
-
-void C_PacketParser::M_GfxEntity(C_Packet& p, bool full)
-{
- std::string name;
- float scale,x,y,angle;
- scale=x=y=angle=0.0f;
- unsigned short id=65535;
- if(full) p >> id >> name >> scale >> x >> y >> angle;
- else p >> id >> x >> y >> angle;
-
- C_Renderer* r=C_Singleton::M_Renderer();
- C_GfxEntity* e=r->M_GetEntity(id);
- if(e)
- {
- e->M_SetPosition(x,y);
- e->M_SetRotation(angle);
- }
- else if(full)
- {
- C_GfxEntity* e=C_GfxEntity::M_Create(id, C_Singleton::M_ModelManager()->M_Get(name), scale);
- e->M_SetPosition(x,y);
- e->M_SetRotation(angle);
- }
-}
-
-void C_PacketParser::M_Model(C_Packet& p)
-{
- unsigned char header;
-
- std::string name;
- p >> name;
-
- std::vector<float> verts;
- p >> header;
- while(header == NET::ModelIndex)
- {
- float f;
- p >> f;
- verts.push_back(f);
- p >> header;
- }
- assert(header == NET::ModelDimensions);
- float w,h;
- p >> w;
- p >> h;
-
- C_Singleton::M_ModelManager()->M_Create(name, verts, w, h);
-}
View
4 renderer.cpp
@@ -62,12 +62,10 @@ void C_Renderer::M_Draw()
{
if((*it)->M_ModelName() == "triangle" || (*it)->M_ModelName() == "bullet") M_Use(C_Singleton::M_ShaderManager()->M_Get("green"));
else M_Use(C_Singleton::M_ShaderManager()->M_Get("minimal"));
- /*
- if((*it)->M_ModelName() == "triangle")
+ if((*it)->IsPlayer())
{
SetView((*it)->GetPosition());
}
- */
glm::mat4 MVP=m_Projection*m_View*(*it)->M_ModelMatrix();
glUniformMatrix4fv(m_MVP, 1, GL_FALSE, glm::value_ptr(MVP));
(*it)->M_Draw();
View
23 server.cpp
@@ -43,15 +43,12 @@ int main()
if(!m->M_Load("box", "box.2dmodel")) exit(1);
if(!m->M_Load("bullet", "bullet.2dmodel")) exit(1);
- C_Entity* top=p->M_CreateDynamicEntity(m->M_Get("horizwall"), 2.0f);
- C_Entity* bottom=p->M_CreateDynamicEntity(m->M_Get("horizwall"), 2.0f);
- C_Entity* left=p->M_CreateDynamicEntity(m->M_Get("vertwall"), 2.0f);
- C_Entity* right=p->M_CreateDynamicEntity(m->M_Get("vertwall"), 2.0f);
+ C_Entity* top=p->M_CreateStaticEntity(m->M_Get("horizwall"), 2.0f);
+ C_Entity* bottom=p->M_CreateStaticEntity(m->M_Get("horizwall"), 2.0f);
+ C_Entity* left=p->M_CreateStaticEntity(m->M_Get("vertwall"), 2.0f);
+ C_Entity* right=p->M_CreateStaticEntity(m->M_Get("vertwall"), 2.0f);
+
std::vector<C_Entity*> boxes;
- boxes.push_back(top);
- boxes.push_back(bottom);
- boxes.push_back(left);
- boxes.push_back(right);
std::vector<C_Entity*> players;
float x=-1.0f;
@@ -71,10 +68,10 @@ int main()
y-=2.0f/rows;
}
- top->M_SetPosition(0,1.0f);
- bottom->M_SetPosition(0,-1.0f);
- left->M_SetPosition(-1.6f,0.0f);
- right->M_SetPosition(1.6f,0.0f);
+ top->M_SetPosition(0,2.0f);
+ bottom->M_SetPosition(0,-2.0f);
+ left->M_SetPosition(-2.0f,0.0f);
+ right->M_SetPosition(2.0f,0.0f);
C_IpAddress ip; unsigned short port;
C_Packet packet;
@@ -131,6 +128,7 @@ int main()
m->M_Get("vertwall") >> packet;
m->M_Get("box") >> packet;
m->M_Get("bullet") >> packet;
+
top->M_DumpFullInstance(packet);
bottom->M_DumpFullInstance(packet);
left->M_DumpFullInstance(packet);
@@ -145,6 +143,7 @@ int main()
{
(*it)->M_DumpFullInstance(packet);
}
+ packet << (unsigned char)NET::PlayerId << e->M_Id();
sock.M_Send(packet, ip, port);
packet.M_Clear();
players.push_back(e);

No commit comments for this range

Something went wrong with that request. Please try again.